Click here to Skip to main content
12,635,132 members (26,976 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
i am doing the application in grid view using check box.

Database field for checkbox is as follows;
Activate datatype bit is used

source code as follows;


<asp:TemplateField HeaderText ="select" HeaderStyle-HorizontalAlign ="left">
     <itemtemplate>
     <asp:CheckBox ID="chkdelete" runat = "server" ForeColor="black" />
     </itemtemplate>



in aspx.cs page code as follows;
for the update the checkbox value to the database.

 protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox txtFName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
        TextBox txtLName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtLName");
        TextBox txtCity = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCity");
        TextBox txtState = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtState");
        TextBox txtCountry = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCountry");
        TextBox txtDescription = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDescription");

        SqlConnection conn = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
        cmd.Connection = conn;
        cmd.CommandText = "UPDATE Vendors SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "'  WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
        conn.Open();
        cmd.ExecuteNonQuery();
        ResultGridView.EditIndex = -1;
        FillVendorGrid();
        conn.Close();
    }

cmd.CommandText = "UPDATE Vendors SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "'  WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";


from the above code for updating check box how to write the code.please help me for how to write the code for check box.

how to write the code in asp.net using csharp.
Posted 12-Dec-12 1:07am
Updated 12-Dec-12 1:09am
v3
Comments
chester_it21 15-Dec-12 8:50am
   
do you mean, want to get value from checkbox or do event update or something when checkbox isChecked or not...??...

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

To Get CheckBox Object

CheckBox chkdelete = (CheckBox)ResultGridView.Rows[e.RowIndex].FindControl("chkdelete");

To pass value for the Field Activate datatype bit use this

,VendorDescription ='" + txtDescription.Text + "',Activate ='" +Convert.ToInt16(chkdelete.Checked) + "'
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100