PLEASE PLEASE HELP ME ,ITS VERY URGENT...
Hi friends,
I am working on checkbox in GRIDVIEW. I want to delete all the selected records... I have this code below for your reference... Please help me to make it work ... Thanks....
protected void btnDelete_Click(object sender, EventArgs e)
{
string currentrow;
for (int index = 0; index <= GridView1.Rows.Count - 1; index++)
{
CheckBox cb = (CheckBox)GridView1.Rows[index].FindControl("chkDelete");
if (cb.Checked)
{
currentrow = GridView1.DataKeys[index].Value.ToString();
string constr = @"Data Source=OM;Initial Catalog=TestDB;Integrated Security=True";
string query = @"Delete FROM Categories where CategoryID='" + currentrow + "'";
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand(query);
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataSet ds = new DataSet();
da.Fill(ds, "Categories");
GridView1.DataSource = ds.Tables["Categories"];
GridView1.DataBind();
}
}
}