473,839 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pre Selecting CheckBoxList

I have some boolean value(1 or 0 ) in a table and i want a databinded
CheckBoxList
to present the selected values on the page..
With CheckBox i know i can se the Checked property like so :-
<asp:CheckBox id="chk" checked=<% Databind.Eval(" This returns 1 or 0")%>
runat="server"% >
Any help how i can do it using CheckBoxList?
Nov 19 '05 #1
2 5239
If your datasource has the columns to define the items in the checkbox list
and the boolean field you can iterate through your data source and use the
boolean field to set the item's selected property. Items in your
checkboxlist must be in the same order of your data source, so you are
sorting a dataview, do so before binding to the checkboxlist. Using a
DataView it would be something like this.

//any sorting you want
checkboxlist.da tasource = dataview;
checkboxlist.da tatextfield = "descriptio n column in data view"
checkboxlist.da tavaluefield = "value column in data view, can be omitted if
same as textfield";
checkboxlist.da tabind();
//iterate through the rows of the dataview with for loop
for(int i = 0; i < dataview.count; i++){
checkboxlist.it ems[i] = (bool)dataview[i]["boolean field"];
}

this is of course untested and obviously pseudocode.
"Patrick.O. Ige" wrote:
I have some boolean value(1 or 0 ) in a table and i want a databinded
CheckBoxList
to present the selected values on the page..
With CheckBox i know i can se the Checked property like so :-
<asp:CheckBox id="chk" checked=<% Databind.Eval(" This returns 1 or 0")%>
runat="server"% >
Any help how i can do it using CheckBoxList?

Nov 19 '05 #2
Thx for the reply John.
'm not using a DataView..
What i have is a Databinded Checkboxlist.
I have the boolean values in a column table how would i loop though the
checkboxlist and retrieve it
I want to retirieve it as TRUE or FALSE so that on getting to the client is
Checked if 1 and unchecked if false or 0
..

"John Teague" <Jo********@dis cussions.micros oft.com> wrote in message
news:B0******** *************** ***********@mic rosoft.com...
If your datasource has the columns to define the items in the checkbox list and the boolean field you can iterate through your data source and use the
boolean field to set the item's selected property. Items in your
checkboxlist must be in the same order of your data source, so you are
sorting a dataview, do so before binding to the checkboxlist. Using a
DataView it would be something like this.

//any sorting you want
checkboxlist.da tasource = dataview;
checkboxlist.da tatextfield = "descriptio n column in data view"
checkboxlist.da tavaluefield = "value column in data view, can be omitted if same as textfield";
checkboxlist.da tabind();
//iterate through the rows of the dataview with for loop
for(int i = 0; i < dataview.count; i++){
checkboxlist.it ems[i] = (bool)dataview[i]["boolean field"];
}

this is of course untested and obviously pseudocode.
"Patrick.O. Ige" wrote:
I have some boolean value(1 or 0 ) in a table and i want a databinded
CheckBoxList
to present the selected values on the page..
With CheckBox i know i can se the Checked property like so :-
<asp:CheckBox id="chk" checked=<% Databind.Eval(" This returns 1 or 0")%> runat="server"% >
Any help how i can do it using CheckBoxList?

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
7953
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all before commercialization took over that was the beauty of the Internet! I've create a checkboxlist validator control...something MS should have done originally in my opinion, but nonetheless here it is. It's a C# control, sort of IE specific. ...
4
8075
by: dm_dal | last post by:
Is there a know issue surrounding the CheckBoxList control and it's viewstate? When my control is created, it's ListItems are checked as needed, but on a postback, they loose their Selected status. David
4
6534
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something like dim li as ListItem li = new ListItem("title","value"); '' how to define here the CSS for List Item, not CheckBoxList?!?!?! myCheckBoxList.Items(x).add(li);
9
1253
by: CCORDON | last post by:
Hi, I have 2 tables, One containing a list of Companies (ID, Name) Another Containing a list of companies a user has acces to (IdUser, IdCompany) The question is how can I load all the companies into a checkBoxList Control and only check the companies that the user currently has access to? Thanks,
5
13400
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able to get a Boolean value TRUE or FALSE when a checkBox is selected. When the checkBoxList was out of the DataList i used "OnSelectedIndexChanged" and it was returning what i wanted but if its in a
4
4048
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to work:( Thanks My CheckBoxList in the DataList Below
4
3120
by: adiweb | last post by:
I would like to use a radiobuttonlist in a windows form control but I know this is not possible because radiobuttonlists are only available in web forms. I am trying to use a checkboxlist instead and I am encountering problems. I do not want multiple checks. Any help is highly appreciated.
5
1405
by: stephen | last post by:
Hi, I have a place holder and I have a checkboxlist in it? why do i get a "System.NullReferenceException: Object reference not set to an instance of an object." error why I try to get the selected value from it? Thanks, Stephen
0
11017
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to the CheckBoxList control in ASP .NET, I had a hard time figuring out how to dynamically select the items that needed to be selected. Specifically, I was displaying checkboxes for Roles, and I wanted to check the boxes of the roles that were...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10908
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10648
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10293
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7828
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3134
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.