Help with CheckBox List!!!!!!!!!

  • Thread starter Thread starter Patrick Olurotimi Ige
  • Start date Start date
P

Patrick Olurotimi Ige

if i do :-
<asp:CheckBoxList id="checkboxlist1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
</asp:CheckBoxList>

and on OnSelectedIndexChanged="Check_Clicked" do :-
Sub Check_Clicked(ByVal sender As Object, ByVal e As EventArgs)
Message.Text = "Selected Item(s):<br><br>"
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>"
End If
Next
End Sub

i can get TRUE as BOOLEAN but if i DataBind the CheckBoxlist it doesn;t
seem to work..

Can anybody tell me what ;m doing wrong?

How should i loop through the selected CheckBoxList when DataBinding?
 
<< it doesn;t seem to work>>
Tell us more. What actually happens?

[Databinding the control] vs [declaring the ListItems explicitly in the
ASPX] should have no effect on your postback code.

So, you might want to see what' actually happening.
1. Compare the code rendered in the browser (compare between the two methods
of populating the items). When you do a View | Source in the browser, does
the CheckBoxList look the same (hard-coded vs bound)?

2. On postback, are you somehow rebinding the CheckBoxList (e.g., possibly
in the Page_Load event). If so, then none of the items would be selected. If
this is the case, then wrap any code that populates the CheckBoxList in
Page_Load in If Not IsPostBack... to ensure that it's getting populated only
on the initial page request.

-HTH
 
Back
Top