ASP.NET - deleteing a row in checkbox - Asked By raju singh on 13-Feb-12 11:20 AM

how to delete a row in gridview when it is checked using asp.net with c sharp and sql..
Web Star replied to raju singh on 13-Feb-12 11:31 AM
On delete button click event just check which checkbox in gridview are checked that will be deleted
http://www.dotnetcurry.com/ShowArticle.aspx?ID=66
http://www.4guysfromrolla.com/articles/052406-1.aspx
dipa ahuja replied to raju singh on 13-Feb-12 11:33 AM
protected void btnDeleteSelected_Click(object sender, EventArgs e)
{
  foreach (GridViewRow row in GridView1.Rows)
  {
 
    if (((CheckBox)row.FindControl("checkBox1")).Checked == true)
    {
      /* Get Table Id From Row */
      string id = GridView1.Rows[row.RowIndex].Cells[0].Text;
 
      /* delete from database */
 
      SqlConnection con = new SqlConnection("Connection String");
      con.Open();
 
      SqlCommand comm = new SqlCommand("delete from TableName where id='" + id + "'", con);
      comm.ExecuteNonQuery();
    }
  }
 
  /* Refresh the Grid*/
}
 
kalpana aparnathi replied to raju singh on 13-Feb-12 01:32 PM
Hi,

For your solution http://www.csharpaspnetarticles.com/2009/04/delete-multiple-rows-gridview-checkbox.html

Regards,