Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/1/30 1:28:18
GridView实现全选及删除源代码_[Asp.Net教程]

GridView实现全选及删除源代码_[Asp.Net教程]
前台代码


后台代码
protected void Button1_Click(object sender, EventArgs e) { if (Button1.Text == "全部选中") { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox2 = (CheckBox)row.Cells[0].FindControl("CheckBox2"); CheckBox2.Checked = true; } Button1.Text = "全部不选"; } else { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox2 = (CheckBox)row.Cells[0].FindControl("CheckBox2"); CheckBox2.Checked = false; } Button1.Text = "全部选中"; } } protected void Button2_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { CheckBox CheckBox2 = (CheckBox)row.Cells[0].FindControl("CheckBox2"); if (CheckBox2.Checked == true) { SqlConnection conn = Fun.InitConn(); SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = "delete from Comment where Comment_ID=’" + row.Cells[2].Text + "’ "; conn.Open(); comm.ExecuteNonQuery(); conn.Close(); } } }


If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759