I have a gridview (just called GridView1) containing a selection of tasks that the user can add to and edit etc. I've added in checkboxes so that the user can select multiple rows at once and the hope is that they can then click on a button to delete those rows.

I picked up some code on the internet that allows me to go through the check boxes, see which ones are checked and then return to a label which tasks would be deleted. It didn't provide the code for actually deleting them however and i havent been able to find out how to do it, so i was hoping someone could help me.

My code is below:

Code:
 
protected void DeleteButton_Click(object sender, GridViewDeleteEventArgs e)
   {
       bool AtLeastOneRowDeleted = false;
 
       foreach (GridViewRow row in GridView1.Rows)
            {
              CheckBox cb = (CheckBox)row.FindControl("chk1");
              if (cb != null && cb.Checked)
                  {
                     AtLeastOneRowDeleted = true;
                    string TaskName = Convert.ToString(GridView1.DataKeys[row.RowIndex].Value);
 
                     DeleteResults.Text += string.Format("This would have deleted task - {0} <br />", TaskName);
 
                     DeleteResults.Visible = AtLeastOneRowDeleted;
                   }
              }
}
I'm linking the gridview by a SQLDataSource linked to a SQL Server 2008 database. I'll probably have to link to it to delete it from there but when i've started to try that they come back with immediate errors.

Any help would be greatly appreciated