Delete Multiple Rows From Gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhagyap
    New Member
    • Nov 2011
    • 14

    #1

    Delete Multiple Rows From Gridview

    Hi..

    I am populating my GridView as follows:
    Code:
    protected void Button1_Click(object sender, EventArgs e)
    {
      string con = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
      SqlDataAdapter sda = new SqlDataAdapter("Select * from DropDownFilter", con);
      sda.Fill(dt);
      GridView1.DataSource = dt;
      GridView1.DataBind();
    }
    And then I have CheckBox for every row. Now I want to delete the checked rows on another button event. How can I achieve this??

    Can anyone please help me??
    Last edited by Frinavale; Jan 3 '12, 08:18 PM. Reason: Added code tags and fixed grammar.
  • Ammu
    New Member
    • Aug 2011
    • 78

    #2
    Code:
    button_click
    {
      foreach (GridViewRow gvr in GridView1.Rows)
      {
        CheckBox chk = (CheckBox)gvr.FindControl("CheckBox1");
        if (chk.Checked==true)
        {
          //delete command         
        }
      }
    }
    Last edited by Frinavale; Jan 3 '12, 08:19 PM. Reason: Added closing "}"

    Comment

    Working...