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
  • #765608
    Hi,

    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.

    Ex:

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


    Hope this will helpful to you...

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

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766392
    Hi
    try this code for Gridview Operations

    Client Side



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



    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);
    sqlcmd.ExecuteNonQuery();
    }
    }
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

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

  • #766897
    foreach or for loop to use for looping the gridview rows

    foreach(GridViewRow rowm in GridView1.rows)
    {
    CheckBox chk =(CheckBox)row.FindControl("Chkdi");
    if(chk!=null && chk,checked)
    {

    do the necessary stuff...
    }
    }

    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


Sign In to post your comments