I have a GirdView table in my application. I have a Delete link button and a checkbox in my first column. Below are snapshots:


I can manually delete each row by clicking Delete link button on each row.
However, I would want to enable the checkbox to delete multiple rows.
Below is my code for my Delete link button:
LinkButton lnk = (LinkButton)sender;
string stid = lnk.CommandArgument.ToString();
SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",stid);
SqlCommand cmd = new SqlCommand(sql,conn);
conn.Open();
cmd.ExecuteNonQuery();
Below is my code for the current Delete Checked button:
bool atLeastOneRowDeleted = false;
foreach (GridViewRow row in GridView1.Rows)
{
// Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("UserSelection");
if (cb != null && cb.Checked)
{
atLeastOneRowDeleted = true;
// How do I get the value from my Employee column?
string userID = ???;
SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",userID);
SqlCommand cmd = new SqlCommand(sql,conn);
conn.Open();
cmd.ExecuteNonQuery();
}
}
I would like to know how should I grep userID, which is Employee key in the GridView, to INSERT it into my SQL delete statement?
