Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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.

C#
 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
Updated 12-Dec-12 0: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

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) + "'
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900