473,406 Members | 2,312 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,406 software developers and data experts.

CheckBoxList in DataList Question?

I have a CheckBoxList in a DataList and i'm trying to get item Selected
after doing a postBack.
I have set my CheckBoxlist AutoPostBack="True"
Any ideas what 'm doing wrong?
It seems not to work:(
Thanks

My CheckBoxList in the DataList Below
-----------------------------------------
<asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>

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

Public Sub Item_Created(ByVal sender As Object, ByVal e As
DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem
Then

Dim cblGroups As CheckBoxList =
CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)

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

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

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

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

If Not (cblGroups Is Nothing) Then
cblGroups.Visible = True
cblGroups.DataSource = DS
'cblGroups.DataMember = "Groups"
cblGroups.DataTextField = "au_lname"
cblGroups.DataValueField = "au_id"
cblGroups.DataBind()

End If
MyConnection.Dispose()
End If

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

Next

End Sub

Nov 19 '05 #1
4 4017
You should familiarize youself with "event bubbling". You will likely need
to handle the CheckBoxList events via the DataList's ItemCommand event
procedure.

This link explains more - while not specifically for the CheckBoxList
control, the information provided will generalize to it.
http://authors.aspalliance.com/hmche...1/Default.aspx

You can google this for more:
"asp.net" + "DataList" + "bubbling"

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
I have a CheckBoxList in a DataList and i'm trying to get item Selected
after doing a postBack.
I have set my CheckBoxlist AutoPostBack="True"
Any ideas what 'm doing wrong?
It seems not to work:(
Thanks

My CheckBoxList in the DataList Below
-----------------------------------------
<asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>

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

Public Sub Item_Created(ByVal sender As Object, ByVal e As
DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem
Then

Dim cblGroups As CheckBoxList =
CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)

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

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

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

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

If Not (cblGroups Is Nothing) Then
cblGroups.Visible = True
cblGroups.DataSource = DS
'cblGroups.DataMember = "Groups"
cblGroups.DataTextField = "au_lname"
cblGroups.DataValueField = "au_id"
cblGroups.DataBind()

End If
MyConnection.Dispose()
End If

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

Next

End Sub


Nov 19 '05 #2
Jeremy thx for the reply.
But is doing this not enough by adding AddHandler in the ItemDataBound like
so:-
AddHandler cblGroups.SelectedIndexChanged, AddressOf
cblGroups_SelectedIndexChanged

Bcos i'm already DataBinding in the ItemDataBound.

My main question that i don't get is can i add the method
SelectedIndexChanged i have set in my checkboxllist to my

ItemDataBound by using the AddHandler?

And if not what would i have to set SelectedIndexChanged in my
DataList1_ItemDataBound and not in my CheckBoxlist.

Thanks



----- Original Message -----
From: "Jeremy S" <A@B.COM>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Sunday, June 19, 2005 5:29 PM
Subject: Re: CheckBoxList in DataList Question?

You should familiarize youself with "event bubbling". You will likely need
to handle the CheckBoxList events via the DataList's ItemCommand event
procedure.

This link explains more - while not specifically for the CheckBoxList
control, the information provided will generalize to it.
http://authors.aspalliance.com/hmche...1/Default.aspx

You can google this for more:
"asp.net" + "DataList" + "bubbling"

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
I have a CheckBoxList in a DataList and i'm trying to get item Selected
after doing a postBack.
I have set my CheckBoxlist AutoPostBack="True"
Any ideas what 'm doing wrong?
It seems not to work:(
Thanks

My CheckBoxList in the DataList Below
-----------------------------------------
<asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>

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

Public Sub Item_Created(ByVal sender As Object, ByVal e As
DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim cblGroups As CheckBoxList =
CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)

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

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

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

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

If Not (cblGroups Is Nothing) Then
cblGroups.Visible = True
cblGroups.DataSource = DS
'cblGroups.DataMember = "Groups"
cblGroups.DataTextField = "au_lname"
cblGroups.DataValueField = "au_id"
cblGroups.DataBind()

End If
MyConnection.Dispose()
End If

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

Next

End Sub



"Jeremy S" <A@B.COM> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl... You should familiarize youself with "event bubbling". You will likely need
to handle the CheckBoxList events via the DataList's ItemCommand event
procedure.

This link explains more - while not specifically for the CheckBoxList
control, the information provided will generalize to it.
http://authors.aspalliance.com/hmche...1/Default.aspx

You can google this for more:
"asp.net" + "DataList" + "bubbling"

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
I have a CheckBoxList in a DataList and i'm trying to get item Selected
after doing a postBack.
I have set my CheckBoxlist AutoPostBack="True"
Any ideas what 'm doing wrong?
It seems not to work:(
Thanks

My CheckBoxList in the DataList Below
-----------------------------------------
<asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>

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

Public Sub Item_Created(ByVal sender As Object, ByVal e As
DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Dim cblGroups As CheckBoxList =
CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)

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

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

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

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

If Not (cblGroups Is Nothing) Then
cblGroups.Visible = True
cblGroups.DataSource = DS
'cblGroups.DataMember = "Groups"
cblGroups.DataTextField = "au_lname"
cblGroups.DataValueField = "au_id"
cblGroups.DataBind()

End If
MyConnection.Dispose()
End If

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

Next

End Sub



Nov 19 '05 #3
You really need to understand event bubbling. Period. When the controls
INSIDE the Datalist fire their events, they get bubbled up through the
containing control (i.e., the DataList). The containing control (DataList)
then fires events that you can handle. There are articles and samples that
describe this far better than I can. Do some research on Event Bubbling -
it's is the thing you need to understand... and simple once understood. It
does not matter that you have added the handler for
cblGroups_SelectedIndexChanged as that particular event will NOT be fired
when your list is contained within a DataList. It would work IF your
checkboxlist was on the page, itself - but it's not. It's hiding inside of a
DataList.

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:uf**************@TK2MSFTNGP15.phx.gbl...
Jeremy thx for the reply.
But is doing this not enough by adding AddHandler in the ItemDataBound
like
so:-
AddHandler cblGroups.SelectedIndexChanged, AddressOf
cblGroups_SelectedIndexChanged

Bcos i'm already DataBinding in the ItemDataBound.

My main question that i don't get is can i add the method
SelectedIndexChanged i have set in my checkboxllist to my

ItemDataBound by using the AddHandler?

And if not what would i have to set SelectedIndexChanged in my
DataList1_ItemDataBound and not in my CheckBoxlist.

Thanks



----- Original Message -----
From: "Jeremy S" <A@B.COM>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Sunday, June 19, 2005 5:29 PM
Subject: Re: CheckBoxList in DataList Question?

You should familiarize youself with "event bubbling". You will likely
need
to handle the CheckBoxList events via the DataList's ItemCommand event
procedure.

This link explains more - while not specifically for the CheckBoxList
control, the information provided will generalize to it.
http://authors.aspalliance.com/hmche...1/Default.aspx

You can google this for more:
"asp.net" + "DataList" + "bubbling"

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
>I have a CheckBoxList in a DataList and i'm trying to get item Selected
> after doing a postBack.
> I have set my CheckBoxlist AutoPostBack="True"
> Any ideas what 'm doing wrong?
> It seems not to work:(
> Thanks
>
>
>
> My CheckBoxList in the DataList Below
> -----------------------------------------
> <asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
> OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>
>
> The itemDataBound I created below:-
> --------------------------------------
>
> Public Sub Item_Created(ByVal sender As Object, ByVal e As
> DataListItemEventArgs) Handles DataList1.ItemDataBound
> If e.Item.ItemType = ListItemType.Item Or _
> e.Item.ItemType = ListItemType.AlternatingItem > Then
>
> Dim cblGroups As CheckBoxList =
> CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)
>
> 'This is where i added the Handler
> AddHandler cblGroups.SelectedIndexChanged, AddressOf Check_Clicked
>
> Dim DS As DataSet
> Dim MyConnection As SqlConnection
> Dim MyCommand As SqlDataAdapter
>
> MyConnection = New
> SqlConnection("server=(local);database=pubs;integr ated security=true;")
> MyCommand = New SqlDataAdapter("select TOP 5 * from Authors", > MyConnection)
>
> DS = New DataSet
> MyCommand.Fill(DS, "Authors")
>
>
> MyConnection.Open()
>
>
>
> If Not (cblGroups Is Nothing) Then
> cblGroups.Visible = True
> cblGroups.DataSource = DS
> 'cblGroups.DataMember = "Groups"
> cblGroups.DataTextField = "au_lname"
> cblGroups.DataValueField = "au_id"
> cblGroups.DataBind()
>
>
>
> End If
> MyConnection.Dispose()
> End If
>
>
>
> End Sub
>
>
> And here the event thats suppose to fire the CheckBoxList below
> ----------------------------------------------------------------
> Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs)
> Dim i As Integer
> For i = 0 To checkboxlist1.Items.Count - 1
> If checkboxlist1.Items(i).Selected Then
> Message.Text = Message.Text &
> checkboxlist1.Items(i).Selected & "<br>"
> Else
> Message.Text = Message.Text & "false <br>"
> End If
>
> Next
>
> End Sub
>
>
>
>
>



"Jeremy S" <A@B.COM> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
You should familiarize youself with "event bubbling". You will likely
need
to handle the CheckBoxList events via the DataList's ItemCommand event
procedure.

This link explains more - while not specifically for the CheckBoxList
control, the information provided will generalize to it.
http://authors.aspalliance.com/hmche...1/Default.aspx

You can google this for more:
"asp.net" + "DataList" + "bubbling"

-HTH

"Patrick.O.Ige" <pa********@optusnet.com.au> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl...
>I have a CheckBoxList in a DataList and i'm trying to get item Selected
> after doing a postBack.
> I have set my CheckBoxlist AutoPostBack="True"
> Any ideas what 'm doing wrong?
> It seems not to work:(
> Thanks
>
>
>
> My CheckBoxList in the DataList Below
> -----------------------------------------
> <asp:checkboxlist id="checkboxlist1" Runat="server" AutoPostBack="True"
> OnSelectedIndexChanged="Check_Clicked"></asp:checkboxlist>
>
> The itemDataBound I created below:-
> --------------------------------------
>
> Public Sub Item_Created(ByVal sender As Object, ByVal e As
> DataListItemEventArgs) Handles DataList1.ItemDataBound
> If e.Item.ItemType = ListItemType.Item Or _
> e.Item.ItemType = ListItemType.AlternatingItem > Then
>
> Dim cblGroups As CheckBoxList =
> CType(e.Item.FindControl("checkboxlist1"), CheckBoxList)
>
> 'This is where i added the Handler
> AddHandler cblGroups.SelectedIndexChanged, AddressOf Check_Clicked
>
> Dim DS As DataSet
> Dim MyConnection As SqlConnection
> Dim MyCommand As SqlDataAdapter
>
> MyConnection = New
> SqlConnection("server=(local);database=pubs;integr ated security=true;")
> MyCommand = New SqlDataAdapter("select TOP 5 * from Authors", > MyConnection)
>
> DS = New DataSet
> MyCommand.Fill(DS, "Authors")
>
>
> MyConnection.Open()
>
>
>
> If Not (cblGroups Is Nothing) Then
> cblGroups.Visible = True
> cblGroups.DataSource = DS
> 'cblGroups.DataMember = "Groups"
> cblGroups.DataTextField = "au_lname"
> cblGroups.DataValueField = "au_id"
> cblGroups.DataBind()
>
>
>
> End If
> MyConnection.Dispose()
> End If
>
>
>
> End Sub
>
>
> And here the event thats suppose to fire the CheckBoxList below
> ----------------------------------------------------------------
> Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs)
> Dim i As Integer
> For i = 0 To checkboxlist1.Items.Count - 1
> If checkboxlist1.Items(i).Selected Then
> Message.Text = Message.Text &
> checkboxlist1.Items(i).Selected & "<br>"
> Else
> Message.Text = Message.Text & "false <br>"
> End If
>
> Next
>
> End Sub
>
>
>
>
>



Nov 19 '05 #4
Def Jeremy i'd get to it.
I haven't just really needed to do much with such scenario.
Thats why i was looking for a solution for now.
Thx
*** 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: plz | last post by:
Is it possible to bind a checkboxlist if this checkboxlist is in a datalist I cant find any tutorials, examples or so about this could somebody help me?
3
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>...
0
by: krzysiek | last post by:
yellow everybody, This what i did is below, however i'm getting error when Checkboxlist shows relation' columns. <asp:DataList id="pytania_list" runat="server" Width="100%" DataSource='<%#...
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. ...
4
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...
1
by: Mike | last post by:
I have a Datalist control on my page that I have binded to a table of available categories. In the Item Template I have a CheckboxList control bound to the products available in each Category. I...
1
by: terminul | last post by:
Hi I have a datalist which loops through the categories and within the datalist I have a CheckBoxList which are bound on the DataList's OnItemDataBound. The only problem I have is retrieving...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...
0
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,...

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.