Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used the checkbox in the gridview.
and create one field in database for checkbox status(fieldname is status).
if checkbox is checked(true) then it save the value 1 in database otherwise 0.
it works perfectly.
But question is that...
How to bind the data in gridview according to checkbox value..
i mean when reloading(next time when gridview displays) the gridview the record which (status)vlaue is 1 must be display as Checked and whose (status)value is 0 must display as Unchecked...
Remember i used CheckBox not CheckBoxList..(dont wanna use CheckBoxList)


I have a Table Name(Project) and its Fields are..
ID(autogenerated), Emp_Name, and Status(Checkbox Status).
i add some data in that table(currently direct in table not using code) like

ID Emp_Name Status
1 ......A
2 ......B
3 ......C
4 ......D
5 ......E

..not added a status that time..
Then i bind this table data in the gridview and added a CheckBox control in the gridview.
When gridview is display suppose i check the check box of Emp_Name A and C.
And press on Save button so it saves the status of that checked button as 1 and status of other record as 0.
so table data is now like

ID Emp_Name Status
1.......A..........1
2.......B..........0
3.......C..........1
4.......D..........0
5.......E..........0

Now when i again run the webpage of that gridview..
the CheckBoxes of the Emp_Name(Records) A and B(whose status is 1) must be displayed as Checked(True)
and other records(checkboxes) must be displayed as Unchecked..
(It means only A and B employees are currently working on the project)
Any suggestions with code??
Posted
Updated 31-Jan-12 22:42pm
v2
Comments
walterhevedeich 1-Feb-12 0:04am    
Not clear. It might be better if you post some code snippets for us to have a better understanding on your problem.
disha desani 1-Feb-12 1:21am    
I have a Table Name(Project) and its Fields are..
ID(autogenerated), Emp_Name, and Status(Checkbox Status).
i add some data in that table(currently direct in table not using code) like

ID Emp_Name Status
1 A
2 B
3 C
4 D
5 E

not added a status that time..
Then i bind this table data in the gridview
and added a CheckBox control in the gridview.
When gridview is display suppose i check the check box of Emp_Name A and C.
And press on Save button so it saves the status of that checked button as 1 and status of other record as 0.
so table data is now like

ID Emp_Name Status
1 A 1
2 B 0
3 C 1
4 D 0
5 E 0


Now when i again run the webpage of that gridview..
the CheckBoxes of the Emp_Name(Records) A and B(whose status is 1) must be displayed as Checked(True) and other records(checkboxes) must be displayed as Unchecked..
(It means only A and B employees are currently working on the project)

If you're using a gridview, then you need to use the dataitembound event to find the checkbox for each row and set if it is checked or not. A CheckBoxList is useless to you in this instance, you could not use one to get a list of check boxes inside a gridview.
 
Share this answer
 
Use TemplateField

XML
<asp:CheckBox ID="uxReqSChbox" runat="server"  Checked='<%#Eval("Status")%>'
                                                           TabIndex="16" />
 
Share this answer
 
 
Share this answer
 
Comments
Member 9364222 15-Oct-12 8:34am    
i have a gridview and a search textbox to search the columns of the gridview.
when the search is completed the design is changed in griview.
It should not change the design of grid.


is there any solution to do so.

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