Wednesday, February 13, 2008

Select check box and delete values from Gridview

for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox c = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
if (c.Checked)
{
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "delete from inbox where mail_id='" + GridView1.Rows[i].Cells[1].Text + "'";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindData();
}
}