Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Getting Databinded CheckBoxlist to display Boolean value ?

Reply
Thread Tools

Getting Databinded CheckBoxlist to display Boolean value ?

 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      07-28-2005
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?



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3JlZWppdGggUmFt?=
Guest
Posts: n/a
 
      07-28-2005
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?
>
>
>
>

 
Reply With Quote
 
 
 
 
Patrick.O.Ige
Guest
Posts: n/a
 
      07-28-2005
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" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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?
> >
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?U3JlZWppdGggUmFt?=
Guest
Posts: n/a
 
      07-29-2005
A DATALIST you need, would look like below
*****************************************
<aspataList 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>
</aspataList>
*****************************************
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" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
> > 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?
> > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Patrick Olurotimi Ige
Guest
Posts: n/a
 
      08-01-2005
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 ***
 
Reply With Quote
 
sana_elka sana_elka is offline
Junior Member
Join Date: Oct 2006
Posts: 1
 
      10-30-2006
I have a datagrid with at least 6 columns. The last column contains an item template with has 5 checkboxes labeled 0,1, 2, 3, 4 . These checkboxes are referred to the level of difficulty of a certain course depending on the value of that item in the database. The name of that item in a database is "Level". I have tried to get it to work but i wasnt able to.
HELP!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtle difference between boolean value and boolean comparison? Metre Meter Javascript 7 08-06-2010 08:40 PM
difference between 'boolean' and 'java.lang.Boolean' J Leonard Java 4 01-19-2008 02:56 AM
Looking for a CheckBoxList(DataBinded) in a DataList sample on the NET Patrick Olurotimi Ige ASP .Net 0 06-22-2005 03:04 AM
How to get Selected item in a Databinded CheckBoxList when CheckBoxlist is in a DataList? Patrick.O.Ige ASP .Net 5 06-19-2005 06:11 AM
How to add DataBinded CheckBoxList in Datalist =?Utf-8?B?UGF0cmljay5PLklnZQ==?= ASP .Net 2 06-17-2005 11:06 AM



Advertisments