471,073 Members | 1,161 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 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 2365
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bryce Budd | last post: by
2 posts views Thread by Patrick.O.Ige | last post: by
reply views Thread by Patrick Olurotimi Ige | last post: by
1 post views Thread by Lynn | last post: by
6 posts views Thread by dbuchanan | last post: by
reply views Thread by leo001 | last post: by

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.