By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,715 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,715 IT Pros & Developers. It's quick & easy.

CheckBoxList in DataList Question?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.