|
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();
}
}
}
This is one point, you can use a query like this:
update ... set ... = ...
where id in (1,2,...)
Get them all at once
In addition, the number of PostBack should be reduced as much as possible to enhance the user experience. Like select all, it should be implemented by JS. |
|