我在GridView中添加了一个button按钮的模板列,此列按钮的事件是为了弹出层。当我没有给弹出层填充数据时,单击按钮,弹出层可以正常执行;当填充完事件之后,弹出层就不显示了,请问什么原因????具体代码如下:protected void Button2_Click(object sender, EventArgs e)
    {   
        
        Button bt = sender as Button;//将sender这个object对象转换成button对象,as转换,获取事件发送者button
         if (bt != null)
         {
             ///Control.NamingContainer属性获取对服务器控件的命名容器的引用,利用button控件的NamingContainer获取GridViewRow(当前行)
             GridViewRow row = bt.NamingContainer as GridViewRow;
            ///FindControl返回的是一个control类型的控件
            ///获取第一列Control控件的集合转换成checkBox类型的控件,
             CheckBox cb = row.Cells[0].FindControl("ck") as CheckBox ;
             if (cb.Checked)
             {
                 ///获取选中checkbox的值
                // string id=GridView1.DataKeys[GridView1 .SelectedIndex ].Value.ToString();
                 string id = GridView1.DataKeys[row.RowIndex].Value.ToString();
                 string constr = ConfigurationManager.ConnectionStrings["Conn"].ToString();
                 OleDbConnection conn = new OleDbConnection(constr);
                 conn.Open();
                 string s = "select * from D_SheList where [ID]=id";
                 DataSet ds = new DataSet();
                 OleDbDataAdapter da = new OleDbDataAdapter(s, conn);
                 da.Fill(ds);
                 if (ds.Tables[0].Rows.Count != 0)
                 {
                     Label2.Text = ds.Tables[0].Rows[0][1].ToString();
                     Label3.Text = ds.Tables[0].Rows[0][2].ToString();
                     Label4.Text = ds.Tables[0].Rows[0][3].ToString();
                     TextBox2.Text = ds.Tables[0].Rows[0][4].ToString();
                     TextBox3.Text = ds.Tables[0].Rows[0][5].ToString();
                     TextBox4.Text = ds.Tables[0].Rows[0][6].ToString();
                     TextBox5.Text = ds.Tables[0].Rows[0][7].ToString();
                     TextBox6.Text = ds.Tables[0].Rows[0][8].ToString();
                     TextBox7.Text = ds.Tables[0].Rows[0][9].ToString();
                     DropDownList3.SelectedValue = ds.Tables[0].Rows[0][10].ToString();
                     ///后台调用前台脚本
                    this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "showid('smallLay')",true );
                 }
                 else {
                     Response.Write("<script>alert('请先选择');</script>");
                 }
               
             }
         }
       
    }

解决方案 »

  1.   

    目测发现填充数据时执行if (ds.Tables[0].Rows.Count != 0) {}
    没有数据时执行 else {                    
      Response.Write("<script>alert('请先选择');</script>");             
         } 
      

  2.   

    可能是我没有表述好。整个button2_click事件中只有调用弹出层的脚本代码时this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "showid('smallLay')",true );整个事件可以执行,出现弹出层。当对弹出层填充数据时,弹出层并不显示