Click here to Skip to main content
15,885,754 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 how to write the checkbox update in the above code. and that checkbox value to be updated in the database.
how to write the code in asp.net using csharp.
Posted
Updated 16-Dec-12 3:16am
v3

1 solution

EVerything about this is bad. You should not string mash SQL like this, I can erase your database by accessing this form. Read up on SQL injection attacks. As for your question, I believe you need, on postback, to search the row in question for the control in question to get it's check state. Overall, I recommend using AJAX instead of the postback mechanism.
 
Share this answer
 

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