for (int i = 0; i < DataList1.Items.Count; i++)
{
CheckBox ck = (CheckBox)DataList1.Items[i].FindControl("select");
if (ck.Checked)
{
int id = Convert.ToInt32(DataList1.DataKeys[i].ToString());
SqlConnection cn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=sa");
cn.Open();
SqlCommand cmd = new SqlCommand("delete from students where ID='" + id + "'", cn);
cmd.ExecuteNonQuery();
cn.Close();
Response.Write("<script>alert('OK')</script>");
}
}
{
CheckBox ck = (CheckBox)DataList1.Items[i].FindControl("select");
if (ck.Checked)
{
int id = Convert.ToInt32(DataList1.DataKeys[i].ToString());
SqlConnection cn = new SqlConnection("server=.;database=pubs;uid=sa;pwd=sa");
cn.Open();
SqlCommand cmd = new SqlCommand("delete from students where ID='" + id + "'", cn);
cmd.ExecuteNonQuery();
cn.Close();
Response.Write("<script>alert('OK')</script>");
}
}