Click here to Skip to main content
15,937,012 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi friends,

am working on asp.net c# and SQLSERVER 2005.

on my webpage i have gridview with checkboxes, user can select only one checkbox from list of checkboxes inside gridview.

In this gridview i have 3 columns as UserName,Password,Status

and also i have submit button outside gridview.

So my requirement is :
----------------------

when user select one checkbox and click on submit button. In Database table it must insert status =1

This must happen when chckbox slected and submit button clicked.

Please can you help me

Thanks.
Posted

Please see the idea to get checkbox details from each row of gridview
foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("CheckBoxID");
                if (cb.Checked)
                {
                //write your code
                }
                else {
                //write your code
                }
            }
 
Share this answer
 
Comments
Member239258 6-Oct-13 3:42am    
Please can you give me the code in detail. am fresher

Thanks in advance.
see i couldn't know your exact code but i am showing you how to do it

foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBoxID");
HiddenField hdnid =(HiddenField) row.FindControl("hdnId");
//Bind your database primary key id in a hidden field, and find it here
if (cb.Checked)
{
//write your code
int ID = Convert.ToInt32(hdnid.Value);
string query = "update tableName set status=1 where id="+ID;
dal.UpadateTable(query);
}
else {
//write your code
}
}
 
Share this answer
 
Comments
Member239258 6-Oct-13 4:27am    
where should i write this code...
Member239258 6-Oct-13 4:35am    
Error in this line..

dal.UpadateTable(query);
[no name] 6-Oct-13 9:01am    
Hello
I have just give one type of solution.
where dal is class object
It mean it should be data access layer class where you should have mentioned your all business logic methods.
DalClass dal=new DalClass();
dal.UpdateTable(query)//It should like this
I am just telling the concept. Hope so you have understood


see the class should be
public class DalClass
{
public void UpdateTable(string query)
{
//Write your sql insert query here to update data in database
}
}

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