473,381 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

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.DataSource = objDR
chkDebtor.DataValueField = "checked" -- this is a column in the
table that returns 1 or 0
chkDebtor.DataTextField = "DebtorCode"
chkDebtor.DataBind()

Dim i As Integer = 0
While i < chkDebtor.Items.Count
chkDebtor.Items(i).Selected =
Microsoft.VisualBasic.IIf((chkDebtor.Items(i).Valu e = "1"), True, False)
System.Math.Min(System.Threading.Interlocked.Incre ment(i),
i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCodeID" but since i need the boolean value i used
the chkDebtor.DataValueField = "checked"
I need the "DebtorCodeID" later in my code.
My question is what other ways can i loop through the checkblxlist without
setting the DataValueField = "checked" but to
DataValueField = "DebtorCodeID"
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 2482
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.DataSource = objDR
chkDebtor.DataValueField = "checked" -- this is a column in the
table that returns 1 or 0
chkDebtor.DataTextField = "DebtorCode"
chkDebtor.DataBind()

Dim i As Integer = 0
While i < chkDebtor.Items.Count
chkDebtor.Items(i).Selected =
Microsoft.VisualBasic.IIf((chkDebtor.Items(i).Valu e = "1"), True, False)
System.Math.Min(System.Threading.Interlocked.Incre ment(i),
i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCodeID" but since i need the boolean value i used
the chkDebtor.DataValueField = "checked"
I need the "DebtorCodeID" later in my code.
My question is what other ways can i loop through the checkblxlist without
setting the DataValueField = "checked" but to
DataValueField = "DebtorCodeID"
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*********@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.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.DataSource = objDR
chkDebtor.DataValueField = "checked" -- this is a column in the table that returns 1 or 0
chkDebtor.DataTextField = "DebtorCode"
chkDebtor.DataBind()

Dim i As Integer = 0
While i < chkDebtor.Items.Count
chkDebtor.Items(i).Selected =
Microsoft.VisualBasic.IIf((chkDebtor.Items(i).Valu e = "1"), True, False)
System.Math.Min(System.Threading.Interlocked.Incre ment(i), i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCodeID" but since i need the boolean value i used
the chkDebtor.DataValueField = "checked"
I need the "DebtorCodeID" later in my code.
My question is what other ways can i loop through the checkblxlist without setting the DataValueField = "checked" but to
DataValueField = "DebtorCodeID"
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="Table" RepeatColumns="3"
runat="server">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1"
checked='<%#CheckYesNo(DataBinder.Eval(Container.D ataItem,
"Checked").ToString())%>' Text='<%#DataBinder.Eval(Container.DataItem,
"Chktext")%>' Runat=server>
</asp:CheckBox>
<asp:Label visible=False Runat=server ID="Label2"
Text='<%#DataBinder.Eval(Container.DataItem, "Chkvalue")%>' >
</asp:Label>
</ItemTemplate>
</asp:DataList>
*****************************************
Please notice the checked='<%#CheckYesNo(DataBinder.Eval(Container.D ataItem,
"Checked").ToString())%>'

this function would look like

protected bool CheckYesNo(string 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='<%#DataBinder.Eval(Container.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*********@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.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.DataSource = objDR
chkDebtor.DataValueField = "checked" -- this is a column in the table that returns 1 or 0
chkDebtor.DataTextField = "DebtorCode"
chkDebtor.DataBind()

Dim i As Integer = 0
While i < chkDebtor.Items.Count
chkDebtor.Items(i).Selected =
Microsoft.VisualBasic.IIf((chkDebtor.Items(i).Valu e = "1"), True, False)
System.Math.Min(System.Threading.Interlocked.Incre ment(i), i - 1)
End While

The above code works
But i have some problems I need another DataValueField which is
"DebtorCodeID" but since i need the boolean value i used
the chkDebtor.DataValueField = "checked"
I need the "DebtorCodeID" later in my code.
My question is what other ways can i loop through the checkblxlist without setting the DataValueField = "checked" but to
DataValueField = "DebtorCodeID"
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/frlrfSystemWebUIWebControlsListItemCollectionClass FindByValueTopic.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
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...
2
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:-...
5
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...
0
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. ...
1
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...
0
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...
0
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...
0
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...
6
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?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.