473,721 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get Selected item in a Databinded CheckBoxList when CheckBoxlist is in a DataList?

I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList is in
a Datalist)

By doing "li.Selecte d = 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
"OnSelectedInde xChanged" and it was returning what i wanted but if its in a
Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Visib le = True

cblGroups.DataS ource = DS

cblGroups.DataT extField = "au_lname"

cblGroups.DataV alueField = "au_id"

cblGroups.DataB ind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selected = True

Next

End If
Nov 19 '05 #1
5 13392
How about binding the datalist to the selectedindexch anged event ;)

You can programaticly bind any event of a control to a method of your
choice (as long as that method has the correct signture)

In VB.NET I think you do it with the AddHandler keyword. So you could in
ItemDataBound write something like:

AddHandler cblGroups.Selec tedIndexChanged , onSelectedIndex Changed
I'm a C# guy so I'm not 100% certain of the syntax but it would point
you in the right direction I think.

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.Ige wrote:
I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList is in
a Datalist)

By doing "li.Selecte d = 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
"OnSelectedInde xChanged" and it was returning what i wanted but if its in a
Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Visib le = True

cblGroups.DataS ource = DS

cblGroups.DataT extField = "au_lname"

cblGroups.DataV alueField = "au_id"

cblGroups.DataB ind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selected = True

Next

End If

Nov 19 '05 #2
Thx Patrick for the reply:)
But when the checkBoxList was out of the DataList i used
onSelectedIndex Changed in the CheckBoxList
like so :-

But your advice is that i should add the "onSelectedInde xChanged " to the
DataList instead of the CheckBoxList?
<asp:checkboxli st id="checkboxlis t1" Runat="server" AutoPostBack="T rue"
onSelectedIndex Changed=""Check _Clicked"></asp:checkboxlis t></td>

Sub Check_Clicked(B yVal sender As Object, ByVal e As EventArgs)

Dim i As Integer

For i = 0 To checkboxlist1.I tems.Count - 1

If checkboxlist1.I tems(i).Selecte d Then

Message.Text = Message.Text & checkboxlist1.I tems(i).Selecte d & "<br>"

Else

Message.Text = Message.Text & "false <br>"

End If

Next

End Sub

"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote
in message news:er******** ******@TK2MSFTN GP10.phx.gbl...
How about binding the datalist to the selectedindexch anged event ;)

You can programaticly bind any event of a control to a method of your
choice (as long as that method has the correct signture)

In VB.NET I think you do it with the AddHandler keyword. So you could in
ItemDataBound write something like:

AddHandler cblGroups.Selec tedIndexChanged , onSelectedIndex Changed
I'm a C# guy so I'm not 100% certain of the syntax but it would point
you in the right direction I think.

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.Ige wrote:
I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList is in a Datalist)

By doing "li.Selecte d = 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
"OnSelectedInde xChanged" and it was returning what i wanted but if its in a Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Visib le = True

cblGroups.DataS ource = DS

cblGroups.DataT extField = "au_lname"

cblGroups.DataV alueField = "au_id"

cblGroups.DataB ind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selected = True

Next

End If

Nov 19 '05 #3
No,

My advice is to use the event on the checkboxlist, but to bind it
dynamicly in the ItemDataBound event.

Is it one checkbox list / item in the datalist?

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.Ige wrote:
Thx Patrick for the reply:)
But when the checkBoxList was out of the DataList i used
onSelectedIndex Changed in the CheckBoxList
like so :-

But your advice is that i should add the "onSelectedInde xChanged " to the
DataList instead of the CheckBoxList?
<asp:checkboxli st id="checkboxlis t1" Runat="server" AutoPostBack="T rue"
onSelectedIndex Changed=""Check _Clicked"></asp:checkboxlis t></td>

Sub Check_Clicked(B yVal sender As Object, ByVal e As EventArgs)

Dim i As Integer

For i = 0 To checkboxlist1.I tems.Count - 1

If checkboxlist1.I tems(i).Selecte d Then

Message.Text = Message.Text & checkboxlist1.I tems(i).Selecte d & "<br>"

Else

Message.Text = Message.Text & "false <br>"

End If

Next

End Sub

"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote
in message news:er******** ******@TK2MSFTN GP10.phx.gbl...
How about binding the datalist to the selectedindexch anged event ;)

You can programaticly bind any event of a control to a method of your
choice (as long as that method has the correct signture)

In VB.NET I think you do it with the AddHandler keyword. So you could in
ItemDataBound write something like:

AddHandler cblGroups.Selec tedIndexChanged , onSelectedIndex Changed
I'm a C# guy so I'm not 100% certain of the syntax but it would point
you in the right direction I think.

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.I ge wrote:
I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList
is in
a Datalist)

By doing "li.Selecte d = 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
"OnSelectedI ndexChanged" and it was returning what i wanted but if its
in a
Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Vi sible = True

cblGroups.Da taSource = DS

cblGroups.Da taTextField = "au_lname"

cblGroups.Da taValueField = "au_id"

cblGroups.Da taBind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selecte d = True

Next

End If


Nov 19 '05 #4
Yes its one CheckBoxList.
But where should it be added?
Public Sub Item_DataBound( ByVal sender As Object, ByVal e As
DataListItemEve ntArgs)
"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote
in message news:uU******** ******@TK2MSFTN GP10.phx.gbl...
No,

My advice is to use the event on the checkboxlist, but to bind it
dynamicly in the ItemDataBound event.

Is it one checkbox list / item in the datalist?

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.Ige wrote:
Thx Patrick for the reply:)
But when the checkBoxList was out of the DataList i used
onSelectedIndex Changed in the CheckBoxList
like so :-

But your advice is that i should add the "onSelectedInde xChanged " to the DataList instead of the CheckBoxList?
<asp:checkboxli st id="checkboxlis t1" Runat="server" AutoPostBack="T rue"
onSelectedIndex Changed=""Check _Clicked"></asp:checkboxlis t></td>

Sub Check_Clicked(B yVal sender As Object, ByVal e As EventArgs)

Dim i As Integer

For i = 0 To checkboxlist1.I tems.Count - 1

If checkboxlist1.I tems(i).Selecte d Then

Message.Text = Message.Text & checkboxlist1.I tems(i).Selecte d & "<br>"

Else

Message.Text = Message.Text & "false <br>"

End If

Next

End Sub

"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote in message news:er******** ******@TK2MSFTN GP10.phx.gbl...
How about binding the datalist to the selectedindexch anged event ;)

You can programaticly bind any event of a control to a method of your
choice (as long as that method has the correct signture)

In VB.NET I think you do it with the AddHandler keyword. So you could in
ItemDataBound write something like:

AddHandler cblGroups.Selec tedIndexChanged , onSelectedIndex Changed
I'm a C# guy so I'm not 100% certain of the syntax but it would point
you in the right direction I think.

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.I ge wrote:

I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList


is in
a Datalist)

By doing "li.Selecte d = 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
"OnSelectedI ndexChanged" and it was returning what i wanted but if its


in a
Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Vi sible = True

cblGroups.Da taSource = DS

cblGroups.Da taTextField = "au_lname"

cblGroups.Da taValueField = "au_id"

cblGroups.Da taBind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selecte d = True

Next

End If


Nov 19 '05 #5
Hi Patrik below is what i have done and still not firing:(
Any ideas what 'm doing wrong?
My CheckBoxList in the DataList Below
-----------------------------------------
<asp:checkboxli st id="checkboxlis t1" Runat="server" AutoPostBack="T rue"
OnSelectedIndex Changed="Check_ Clicked"></asp:checkboxlis t>

The itemDataBound I created below:-
--------------------------------------

Public Sub Item_Created(By Val sender As Object, ByVal e As
DataListItemEve ntArgs) Handles DataList1.ItemD ataBound
If e.Item.ItemType = ListItemType.It em Or _
e.Item.ItemType = ListItemType.Al ternatingItem
Then

Dim cblGroups As CheckBoxList =
CType(e.Item.Fi ndControl("chec kboxlist1"), CheckBoxList)

'This is where i added the Handler
AddHandler cblGroups.Selec tedIndexChanged , AddressOf Check_Clicked

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection(" server=(local); database=pubs;i ntegrated security=true;" )
MyCommand = New SqlDataAdapter( "select TOP 5 * from Authors",
MyConnection)

DS = New DataSet
MyCommand.Fill( DS, "Authors")
MyConnection.Op en()

If Not (cblGroups Is Nothing) Then
cblGroups.Visib le = True
cblGroups.DataS ource = DS
'cblGroups.Data Member = "Groups"
cblGroups.DataT extField = "au_lname"
cblGroups.DataV alueField = "au_id"
cblGroups.DataB ind()

End If
MyConnection.Di spose()
End If

End Sub
And here the event thats suppose to fire the CheckBoxList below
----------------------------------------------------------------
Sub Check_Clicked(B yVal sender As Object, ByVal e As EventArgs)
Dim i As Integer
For i = 0 To checkboxlist1.I tems.Count - 1
If checkboxlist1.I tems(i).Selecte d Then
Message.Text = Message.Text &
checkboxlist1.I tems(i).Selecte d & "<br>"
Else
Message.Text = Message.Text & "false <br>"
End If

Next

End Sub


"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote
in message news:uU******** ******@TK2MSFTN GP10.phx.gbl...
No,

My advice is to use the event on the checkboxlist, but to bind it
dynamicly in the ItemDataBound event.

Is it one checkbox list / item in the datalist?

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.Ige wrote:
Thx Patrick for the reply:)
But when the checkBoxList was out of the DataList i used
onSelectedIndex Changed in the CheckBoxList
like so :-

But your advice is that i should add the "onSelectedInde xChanged " to the DataList instead of the CheckBoxList?
<asp:checkboxli st id="checkboxlis t1" Runat="server" AutoPostBack="T rue"
onSelectedIndex Changed=""Check _Clicked"></asp:checkboxlis t></td>

Sub Check_Clicked(B yVal sender As Object, ByVal e As EventArgs)

Dim i As Integer

For i = 0 To checkboxlist1.I tems.Count - 1

If checkboxlist1.I tems(i).Selecte d Then

Message.Text = Message.Text & checkboxlist1.I tems(i).Selecte d & "<br>"

Else

Message.Text = Message.Text & "false <br>"

End If

Next

End Sub

"Patrik L÷wendahl [C# MVP]" <pa************ *************** ***@home.se> wrote in message news:er******** ******@TK2MSFTN GP10.phx.gbl...
How about binding the datalist to the selectedindexch anged event ;)

You can programaticly bind any event of a control to a method of your
choice (as long as that method has the correct signture)

In VB.NET I think you do it with the AddHandler keyword. So you could in
ItemDataBound write something like:

AddHandler cblGroups.Selec tedIndexChanged , onSelectedIndex Changed
I'm a C# guy so I'm not 100% certain of the syntax but it would point
you in the right direction I think.

--
Patrik L÷wendahl [C# MVP]
http://www.lowendahl.net/ || http://www.cshrp.net
Please reply only to the newsgroup.

Patrick.O.I ge wrote:

I'm binding a CheckBoxlist below in the ItemDataBound(t he CheckBoxList


is in
a Datalist)

By doing "li.Selecte d = 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
"OnSelectedI ndexChanged" and it was returning what i wanted but if its


in a
Datalist

and 'm Binding the CheckBoxList in ItemBound how can i get to it?

Any ideas?

If Not (cblGroups Is Nothing) Then

cblGroups.Vi sible = True

cblGroups.Da taSource = DS

cblGroups.Da taTextField = "au_lname"

cblGroups.Da taValueField = "au_id"

cblGroups.Da taBind()

For Each li As ListItem In cblGroups.Items

' I get all the CheckBoxes selected by doing below

li.Selecte d = True

Next

End If


Nov 19 '05 #6

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

Similar topics

1
3324
by: Peter | last post by:
How can I check which items has been selected in CheckBoxList control when I bind data to it from SQL Server? The code I use works fine when I add manually items into checkboxlist control, but does not work when I bind it. String s = "Selected items:<br>" for (int i=0; i < CheckBoxList1.Items.Count; i++) if ( CheckBoxList1.Items.Selected ) // List the selected item s = s + CheckBoxList1.Items.Text
3
2885
by: Ed West | last post by:
Hello I am trying to put a CheckBoxList in a DataList but it's not working too great. Is this possible? <asp:datalist id=DataList1 runat="server" RepeatColumns="4"> <HeaderTemplate> <asp:CheckBoxList id=states runat=server> </HeaderTemplate> <ItemTemplate>
4
6549
by: krzysiek | last post by:
hello, i have several radiolists and checkboxlist that are generated dinamicly based on datasource. So frankly speaking i don't know names and number of that web controls cose they are always different. How can i retreive selected values from those controls ?
1
4455
by: rbscheer | last post by:
Hi. Is there any way to count how many items are selected on a CheckBoxList control without iterating throug the items? I have a For...Next loop that only needs to be taken into action if the CheckBoxList control has at least one selected item. Thanks, Robert Scheer
2
2097
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?
3
1585
by: xianxian | last post by:
Hi guys, I'm having trouble getting my Datagrid to display according to Checkboxes checked values. On my Checkboxes, I have 5 values :- 1) Apartment/Condo 2) Executive Condo 3) Detached 4) Semi-detached
4
2515
by: Patrick.O.Ige | last post by:
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
4
15996
by: Chris Kettenbach | last post by:
Good morning all, I am sure this has been asked but I did not see anything. I have a datalist control. In the edititemtemplate I have a dropdownlist. I know on the itemdatabound event is where I can set the dropdownlist selectedindex. How do I set the correct value? private void lstDegrees_ItemDataBound(object sender, DataListItemEventArgs e) {
4
4461
by: Brett Wesoloski | last post by:
I am having a bit of a problem getting the current value of the checkbox list. I have tried using the selected value as I thought that would give me the current value of the check box but it appears to be giving me the first value that is selected all the time. I have also tried to use the selectedItem property but that does the same as I would expect becuase the property says it get the item with the lowest value.
0
8738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
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
9234
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
9150
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
9086
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
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4501
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...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2146
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.