You must Sign In to post a response.
  • Category: ASP.NET

    Checkbox in gridview database operations

    i want to insert to database checkboxed in gridview checked value and next i want to see in gridview griedview if checked
  • #765607

    I'm not clear about your requirement, but as per my understanding you want to insert the checked records into database right. If your requirement is like above then refer below sample.


    Protected void btnSave_Click(object sender, EventArgs e)
    foreach(GridViewRow row in gv.Rows)
    CheckBox chk=row.FindControl("chkSelect") as CheckBox;
    //insert data in to database.

    Hope this will helpful to you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765610
    Use findcontrol method of gridview row or cell to check if gridview checkbox is checked, see below snippet
    Loop on each row and check
    see below snippet

    foreach (GridViewRow row in GridView1.Rows)
    CheckBox chk = row.Cells[0].Controls[0] as CheckBox;
    if (chk != null && chk.Checked)
    // ...

    OR use in onrowcommand event and get cheked checkbox value.

    GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
    int requisitionId = Convert.ToInt32(e.CommandArgument);
    CheckBox cbox = (CheckBox)row.Cells[3].Controls[0];

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766393
    try this code for Gridview Operations

    Client Side

    <asp:GridView ID="GridView211" runat="server" AutoGenerateSelectButton="True">
    <asp:TemplateField HeaderText="IsApproved">
    <asp:CheckBox ID="chkApproved" runat="server" CommandName="Approve" AutoPostBack="false" />

    Server Side

    protected void Btnsubmits_Click(object sender, EventArgs e)
    foreach (GridViewRow row in GridView1.Rows)
    CheckBox chk = (CheckBox)row.FindControl("chkApproved");
    if (chk != null && chk.Checked)
    SqlCommand sqlcmd = new SqlCommand("Insert into Tblcity values('Chennai');", con);

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments