GridView复选框的问题
前台:<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField HeaderText="选择" >
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="提交" />
<asp:Label ID="Label1" runat="server"></asp:Label>
后台:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection sqlconstr = new SqlConnection();
sqlconstr.ConnectionString = "server = localhost;database = xuanke; Trusted_Connection=SSPI";
string safeSql = "Select * FROM kecheng";
SqlCommand cmd = new SqlCommand(safeSql, sqlconstr);
sqlconstr.Open();
SqlDataReader myReader = cmd.ExecuteReader();
this.GridView1.DataSource = myReader;
GridView1.DataBind();
sqlconstr.Close();
}
protected void Button1_Click1(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)GridView1.Rows[1].Cells[0].FindControl("CheckBox1");
if (cb.Checked)
Label1.Text = "123";
}
为什么点击checkbox没反应