|
发表于 2020-7-22 10:15:01
|
显示全部楼层
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)
{
string connStr = ConfigurationManager.AppSettings["LawConnStr"];
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "delete from pictures_pic where pid='" + row.Cells[2].Text + "' ";
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
}
}
这是一点,可以用类似这样的查询啊:
update ... set ...= ...
where id in (1,2,...)
一次把它们搞定
另外,应当尽量减少PostBack的次数,以增强用户体验.像全选之类的,就应该让JS去实现. |
|