CheckBoxList in DataList Question?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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;integrated 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





.



Relevant Pages

  • Re: Adding dropdownlist to a datalist
    ... "Karl" wrote: ... > ItemDataBound isn't invoked on postback because the control isn't databound ... > Private Sub List_ItemDataBound(ByVal sender As Object, ... > DataListItemEventArgs) Handles list.ItemDataBound ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: label in footertemplate of datagrid
    ... Sub dlCart_ItemDataBound(sender As Object, e As DataListItemEventArgs) ... dblTotal = 'calling a function which returns a Double ... Dim TotalLabel As Label = CType, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: CheckBoxList in DataList Question?
    ... AddHandler cblGroups.SelectedIndexChanged, AddressOf ... >> Public Sub Item_Created(ByVal sender As Object, ... >> DataListItemEventArgs) Handles DataList1.ItemDataBound ... >> AddHandler cblGroups.SelectedIndexChanged, AddressOf Check_Clicked ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DataList and [bound] ListBox
    ... "Beorn" wrote in message ... the adjusted price is show ... > Sub Page_Load ... e As DataListItemEventArgs) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DataList and [bound] ListBox
    ... "Beorn" wrote in message ... the adjusted price is show ... > Sub Page_Load ... e As DataListItemEventArgs) ...
    (microsoft.public.dotnet.framework.aspnet)