![]() |
#2
sldtk12008-06-05 01:20
这个是我原来做全选并删除时写的代码,希望对楼主有用
protected void Button1_Click(object sender, EventArgs e) { if (Button1.Text == "全部选中") { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox1 = (CheckBox)row.Cells[0].FindControl("CheckBox1"); CheckBox1.Checked = true; } Button1.Text = "全部不选"; } else { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox1 = (CheckBox)row.Cells[0].FindControl("CheckBox1"); CheckBox1.Checked = false; } Button1.Text = "全部选中"; } } protected void Button2_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox1 = (CheckBox)row.Cells[0].FindControl("CheckBox1"); if (CheckBox1.Checked == true) { SqlConnection con = DB.createCon(); SqlCommand cmd = new SqlCommand("delete from customer where customer_id='" + row.Cells[0].Text + "'", con); con.Open(); cmd.ExecuteNonQuery(); GridView1.DataBind(); con.Close(); } } } |
我的GridView的第一列是CheckBox模板列,然后这列的footertemplate模板里面放了一个checkbox(用做全选)
我给这个checkbox添加了事件(CheckALL),然后报错,说:
BC30408: 方法“Public Sub CheckALL()”没有与委托“Delegate Sub EventHandler(sender As Object, e As System.EventArgs)”相同的签名。
请问,给模板列里的空间添加事件,和平常我们添加事件一样吗?(如CheckBox:OnCheckChanged="CheckAll")
如果不一样,改怎么给一个空间添加事件?
谢谢