Click here to Skip to main content
15,914,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear all,

how to update gridview checkbox selected value as 1 to database in asp.net
=============================================================

I have 3 columns in database table, Username,password,Status

on my webpage i have gridview with checkboxes in it. Only user can select one checkbox.

and below this gridview i have submit button to store checked value in database as 1.

Please can you help me.

after selecting checkbox, user will click on submit button. then the value will save in database as 1.

help is appreciated.


Thanks.
Posted
Comments
Azee 6-Oct-13 6:06am    
Any progress that you have made so far?
Member239258 6-Oct-13 6:19am    
This is my progress on submit button

protected void BtnSubmit_Click(object sender, ImageClickEventArgs e)
{


SqlConnection con = new SqlConnection(_connString);
con.Open();
foreach (GridViewRow row in GVMessagesDisplay.Rows)
{
int key = (int)GVMessagesDisplay.DataKeys[row.RowIndex].Value;
CheckBox cb = (CheckBox)row.FindControl("CheckOne");
SqlCommand cmd = new SqlCommand("UPDATE Messages SET Status = " + cb.Checked + " Where Id=" + key.ToString(), con);
cmd.ExecuteNonQuery();
}
con.Close();


}

but it shows error

Invalid column name 'False'.

Please can you help me

thanks....
Thanks7872 6-Oct-13 7:48am    
Change this in you code:
SqlCommand cmd = new SqlCommand("UPDATE Messages SET Status = '1' Where Id='" + key.ToString()+"'", con);

1 solution

if the data type of status column in your table is of BIT type then you have to paas 0 or 1 from your application means if you pass true or false as a string in your table then this thrown an error.
 
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