473,473 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagird checkbox populating

63 New Member
Expand|Select|Wrap|Line Numbers
  1.         Dim i As Integer
  2.         Dim dr As SqlDataReader
  3.         Dim objDataAccess As New DataAccess.DataAccess
  4.         dr = objDataAccess.getThirdLevelPrevileges(CInt(ddlUserGroup.SelectedValue))
  5.         clearCheckedListBox()
  6.  
  7.         While dr.Read()
  8.  
  9.             If dr.Item("Status") = True Then
  10.                 chkLevel3.Items.Add(dr.Item("Level3"), True)
  11.             Else
  12.                 chkLevel3.Items.Add(dr.Item("Level3"))
  13.             End If
  14.  
  15.         End While
  16.  
  17.  
I am bringing value from data base and trying to bind in the above shown way.
Some check boxes are not checked as per the database.
Can anyone help me please?


paulson
Mar 18 '08 #1
1 865
nateraaaa
663 Recognized Expert Contributor
You need to loop through your datagrid and use the FindControl method to find the checkbox control in each row.

Expand|Select|Wrap|Line Numbers
  1.  DataTable dataTable = dataset.Tables[0]; 
  2. for(int i = 0; i < dataGrid1.Items.Count; i ++)
  3. {
  4. DataRow row = dataTable.Rows[i];
  5. bool checkBoxChecked = Convert.ToBoolean(row["checkBoxValue"]);
  6. CheckBox chk = (CheckBox)dataGrid1.Items[i].FindControl("CheckBox1");
  7. if(checkBoxChecked)
  8. {
  9. chk.Checked = true;
  10. }
  11. else
  12. {
  13. chk.Checked = false;
  14. }
  15. }
  16.  
Give this a try.

Nathan
Mar 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: timon | last post by:
I have create a Datagird in the window form. How can I set the column name in the datagird?
3
by: C | last post by:
Hi, I have an asp server side checkbox as below. I have a page where users can edit their user record. I set this checkbox to true based on a value in a database. <asp:checkbox...
1
by: segue | last post by:
I'm dynamically creating/populating a checkbox list and adding it to a web form. I want to when checking an item in the list have the autopostback retrieve the selected item. I'm dynamically...
17
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5...
4
by: wink martindale | last post by:
Hello All, I am certain this has been asked before, but here goes: How do I add a checkbox to a datagrid that is not related to a field in the database? This checkbox will enable the user to...
3
by: tom-co | last post by:
Hi. I am using this code so that when a checkbox is selected it populates two separate textfields with the word "No". <script type="text/javascript"><!-- function setField(what) { if...
3
by: gvi | last post by:
Hi Not sure if this is answered b4. I have a label, 2 textboxes and 1 check box in a datagrid . If I check the checkbox 2nd textbox should be disabled. Is there any way I could do this in...
4
by: Matt | last post by:
I am no JavaScript guru so please bear with me and be as detailed as possible with your response. I thank you in advance. I have an ASP page that contains form elements. I also have an inline...
3
by: Chris McGrath | last post by:
Hello all, I have a gridview that contains a checkbox for each row and in each row, one of the fields is an asp:HyperLinkField. What I am trying to do is allow a user to click the link and...
6
by: dmorand | last post by:
I'm populating some checkboxes from a query result. I'm having a problem retrieving the data to file it to my database. How do I retrieve the checkbox values when the names are variable names? I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.