Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Use of collection example
01-25-2011, 06:31 PM #1
- Join Date
- Jan 2010
- Thanked 0 Times in 0 Posts
Use of collection example
I've been exploring some of the options .NET has to offer and right now i'm on the "CheckBoxList".
The issue I've been having with it is that I've been trying to create a list with key/value pairs.
That said, I've been using "Hashtable" and "SortedList".
My issue now is that I'd like to display a checkbox list in a particular order and these 2 options don't allow me to do so.
I've now understood that I have to use the Collection Object but since I've been learning based on the w3school examples I am not sure how to properly use them. (binding doesn't work)
Can anyone provide me with an ASP.NET example?
Thanks in advance!
Here is the example I've been working on:
<script runat="server"> Sub Page_Load if Not Page.IsPostBack then dim mycounties=New Collection mycounties.Add("N","Norwich") mycounties.Add("S","Scotland") mycounties.Add("F","Farnbrough") mycounties.Add("E","England") rb.DataSource=mycounties rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() end if end sub sub displayMessage(s as Object,e As EventArgs) lbl1.text="Your favorite country is: " & rb.SelectedItem.Text end sub </script> <html> <body> <form runat="server"> <asp:CheckBoxList id="rb" runat="server" AutoPostBack="True" RepeatDirection="Vertical" RepeatColumns="4" RepeatLayout="Table" onSelectedIndexChanged="displayMessage" /> <p><asp:label id="lbl1" runat="server" /></p> </form> </body> </html>