title: delete multiple rows in gridview using checkboxes
body: <p>i have used following code to execute my query of deleting multiple values in gridview using checkboxes but when i execute the following it says checkbox1.checked is false but i check that . It doesnot delte my selected values </p>
  
  <p>here is my code and script part</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
  {
      if (!Page.IsPostBack)
      {
          grd_bnd();
      }
  }
   private void grd_bnd()
  {
   SqlConnection con = new        SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
      SqlCommand cmd = new SqlCommand("select * from student", con);
      con.Open();
      SqlDataAdapter adp = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      adp.Fill(ds);
      GridView1.DataSource = ds;
      GridView1.DataBind();
      con.Close();
  }
  protected void Button3_Click(object sender, EventArgs e)
  {
      foreach (GridViewRow row in GridView1.Rows)
      {
          CheckBox checkbox1 = (CheckBox)row.FindControl("checkboxdelete");
          if (checkbox1.Checked)
          {
              int rollno = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value.ToString());
              //CheckBox checkbox1 = (CheckBox)row.FindControl("checkbox1");
              SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
              SqlCommand cmd = new SqlCommand("delete from student where rollno = @rollno ", con);
              cmd.CommandType = CommandType.Text;
              cmd.Parameters.Add("@rollno", SqlDbType.Int).Value = rollno.ToString();
              con.Open();
              cmd.ExecuteNonQuery();
              con.Close();
              cmd.Dispose();
          }
      }
      grd_bnd();
  }
  }
  </code></pre>
  
  <p>and here is script </p>
  
  <pre><code>      &lt;asp:GridView ID="GridView1" runat="server" DataKeyNames="rollno" AllowSorting="true" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" &gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField HeaderText="Select"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox ID="checkboxdelete" runat="server" /&gt;
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Name"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblname" runat ="server" Text='&lt;%#Eval("name") %&gt;' /&gt; 
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Roll No."&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblrollno" runat ="server" Text='&lt;%#Eval("rollno") %&gt;' /&gt; 
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Batch"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblbatch" runat ="server" Text='&lt;%#Eval("batch") %&gt;' /&gt; 
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Course"&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblcourse" runat ="server" Text='&lt;%#Eval("course") %&gt;' /&gt; 
                  &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
          &lt;/gridview&gt;
          &lt;asp:Button ID="Button3" runat="server" Font-Bold="True" Text="Delete Selected" ForeColor="#000066" OnClick="Button3_Click" /&gt;
      &lt;asp:Label ID="Label1" runat="server" ForeColor="#666666"&gt;&lt;/asp:Label&gt;
  </code></pre>