473,856 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Databinded CheckBoxlist to display Boolean value ?

I'm DataBinding a CheckBoxList and i want to get the checkboxes selected
when the page is loaded depending on a Boolean value from the Database..
chkDebtor.DataS ource = objDR
chkDebtor.DataV alueField = "checked" -- this is a column in the
table that returns 1 or 0
chkDebtor.DataT extField = "DebtorCode "
chkDebtor.DataB ind()

Dim i As Integer = 0
While i < chkDebtor.Items .Count
chkDebtor.Items (i).Selected =
Microsoft.Visua lBasic.IIf((chk Debtor.Items(i) .Value = "1"), True, False)
System.Math.Min (System.Threadi ng.Interlocked. Increment(i),
i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCode ID" but since i need the boolean value i used
the chkDebtor.DataV alueField = "checked"
I need the "DebtorCode ID" later in my code.
My question is what other ways can i loop through the checkblxlist without
setting the DataValueField = "checked" but to
DataValueField = "DebtorCode ID"
Is there a way to get the Checked boolean values and pass it to the
checkboxlist to get False or TRUE?

Nov 19 '05 #1
4 2523
I think, A while back I faced a similar problem and I found it easier to use
a Repeater control with checkboxes in it instead of a CheckBoxList

While using Repeater control, you will be able to easily achive this with the
ItemDataBound event..

pls let me know , if you need help in implementing this with Repeater

Sreejith

"Patrick.O. Ige" wrote:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected
when the page is loaded depending on a Boolean value from the Database..
chkDebtor.DataS ource = objDR
chkDebtor.DataV alueField = "checked" -- this is a column in the
table that returns 1 or 0
chkDebtor.DataT extField = "DebtorCode "
chkDebtor.DataB ind()

Dim i As Integer = 0
While i < chkDebtor.Items .Count
chkDebtor.Items (i).Selected =
Microsoft.Visua lBasic.IIf((chk Debtor.Items(i) .Value = "1"), True, False)
System.Math.Min (System.Threadi ng.Interlocked. Increment(i),
i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCode ID" but since i need the boolean value i used
the chkDebtor.DataV alueField = "checked"
I need the "DebtorCode ID" later in my code.
My question is what other ways can i loop through the checkblxlist without
setting the DataValueField = "checked" but to
DataValueField = "DebtorCode ID"
Is there a way to get the Checked boolean values and pass it to the
checkboxlist to get False or TRUE?

Nov 19 '05 #2
Yes i think i would need to look at Repeater then.
It would be nice if you can provide me some info.
Thx
"Sreejith Ram" <Sr*********@di scussions.micro soft.com> wrote in message
news:DC******** *************** ***********@mic rosoft.com...
I think, A while back I faced a similar problem and I found it easier to use a Repeater control with checkboxes in it instead of a CheckBoxList

While using Repeater control, you will be able to easily achive this with the ItemDataBound event..

pls let me know , if you need help in implementing this with Repeater

Sreejith

"Patrick.O. Ige" wrote:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected
when the page is loaded depending on a Boolean value from the Database..
chkDebtor.DataS ource = objDR
chkDebtor.DataV alueField = "checked" -- this is a column in the table that returns 1 or 0
chkDebtor.DataT extField = "DebtorCode "
chkDebtor.DataB ind()

Dim i As Integer = 0
While i < chkDebtor.Items .Count
chkDebtor.Items (i).Selected =
Microsoft.Visua lBasic.IIf((chk Debtor.Items(i) .Value = "1"), True, False)
System.Math.Min (System.Threadi ng.Interlocked. Increment(i), i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCode ID" but since i need the boolean value i used
the chkDebtor.DataV alueField = "checked"
I need the "DebtorCode ID" later in my code.
My question is what other ways can i loop through the checkblxlist without setting the DataValueField = "checked" but to
DataValueField = "DebtorCode ID"
Is there a way to get the Checked boolean values and pass it to the
checkboxlist to get False or TRUE?

Nov 19 '05 #3
A DATALIST you need, would look like below
*************** *************** ***********
<asp:DataList id="DataList1" RepeatDirection ="Horizontal "
RepeatLayout="T able" RepeatColumns=" 3"
runat="server">
<ItemTemplate >
<asp:CheckBox ID="Checkbox1"
checked='<%#Che ckYesNo(DataBin der.Eval(Contai ner.DataItem,
"Checked").ToSt ring())%>' Text='<%#DataBi nder.Eval(Conta iner.DataItem,
"Chktext")% >' Runat=server>
</asp:CheckBox>
<asp:Label visible=False Runat=server ID="Label2"
Text='<%#DataBi nder.Eval(Conta iner.DataItem, "Chkvalue") %>' >
</asp:Label>
</ItemTemplate>
</asp:DataList>
*************** *************** ***********
Please notice the checked='<%#Che ckYesNo(DataBin der.Eval(Contai ner.DataItem,
"Checked").ToSt ring())%>'

this function would look like

protected bool CheckYesNo(stri ng val)
{
if(val=="1")
return(true);

return(false);
}

*************** *************** ***********

Value/ID that you do not want to display , but still store with checkbox

<asp:Label visible=False Runat=server ID="Label1"
Text='<%#DataBi nder.Eval(Conta iner.DataItem, "Chkvalue") %>' > </asp:Label>

*************** *************** ***********
hope this helps

"Patrick.O. Ige" wrote:
Yes i think i would need to look at Repeater then.
It would be nice if you can provide me some info.
Thx
"Sreejith Ram" <Sr*********@di scussions.micro soft.com> wrote in message
news:DC******** *************** ***********@mic rosoft.com...
I think, A while back I faced a similar problem and I found it easier to

use
a Repeater control with checkboxes in it instead of a CheckBoxList

While using Repeater control, you will be able to easily achive this with

the
ItemDataBound event..

pls let me know , if you need help in implementing this with Repeater

Sreejith

"Patrick.O. Ige" wrote:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected
when the page is loaded depending on a Boolean value from the Database..
chkDebtor.DataS ource = objDR
chkDebtor.DataV alueField = "checked" -- this is a column in the table that returns 1 or 0
chkDebtor.DataT extField = "DebtorCode "
chkDebtor.DataB ind()

Dim i As Integer = 0
While i < chkDebtor.Items .Count
chkDebtor.Items (i).Selected =
Microsoft.Visua lBasic.IIf((chk Debtor.Items(i) .Value = "1"), True, False)
System.Math.Min (System.Threadi ng.Interlocked. Increment(i), i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCode ID" but since i need the boolean value i used
the chkDebtor.DataV alueField = "checked"
I need the "DebtorCode ID" later in my code.
My question is what other ways can i loop through the checkblxlist without setting the DataValueField = "checked" but to
DataValueField = "DebtorCode ID"
Is there a way to get the Checked boolean values and pass it to the
checkboxlist to get False or TRUE?


Nov 19 '05 #4
Sreejith thx for the hint..
Using DataList was a good workaround but after thinking over the weekend
i came out with a solution using
FindByValue Method of the LisItem Collection which searches the
collection for a ListItem with a Value property that contains the
specified value and what i did is if it finds the value i set the
checkbox to TRUE.But if it doesn't it returns NOTHING..
See the Msdn documentation here:-
http://msdn.microsoft.com/library/de.../en-us/cpref/h
tml/frlrfSystemWebU IWebControlsLis tItemCollection ClassFindByValu eTopic.a
sp
Patrick
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5

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. ...
2
2100
by: Patrick.O.Ige | last post by:
Is it possible to bind a checkboxlist if this checkboxlist is in a datalist Bcos when i add a CheckBoxlist to a Datalist i get :- Object reference not set to an instance of an object error at:- checkboxlist1.DataSource = myDataSet Why?
5
13401
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
0
1104
by: Patrick Olurotimi Ige | last post by:
I have a CheckBoxList(which is Databinded) in a Datalist. My DataBinded is done in the onItemDataBound I'm using this method below to select the selected item in a DataBinded CheckBoxList. Everything works fine but when i tick a checkbox i get the error at line:- For i = 0 To checkboxlist1.Items.Count - 1 Object reference not set to an instance of an object.
1
1208
by: Lynn | last post by:
Hello, I have a page that allows the person to select multiple items from a checkboxlist. The checkboxlist is being populated from a table in the database. The user's selections are sent to the database as a comma separated list (ex. 17, 22, 35). I also have a page that allows the user to edit existing records. I am unsure of how to build the checkboxlist on the edit page and have the various checkboxes checked based on what is in the...
0
2165
by: webmaster | last post by:
Hi all, I'm tearing my hair out with this one. I have successfully implemented by own RadioButtonList in order to provide additional functionality and a DIV rather than TABLE-based layout in one of my ASP.NET 1.1 web forms. This involves a fairly simple inheritance of the System.Web.UI.WebControls.RadioButtonList class, with some new properties added and the Render sub overridden. When I come to render each radio item, I do the...
0
2184
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"> <EditItemTemplate>
0
2425
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1"> <EditItemTemplate>
6
3515
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
0
9920
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
11063
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
10699
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
10790
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
10390
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
9535
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...
0
5762
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...
1
4580
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 we have to send another system
3
3203
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.