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

  • Thread starter Patrick Olurotimi Ige
  • 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?
 
B

Brock Allen

You can set the Selected value of the items in a CheckBoxList to ensure they're
checked.
 
J

Jeremy S

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top