Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filling a dropdown list with a HashTable

Posted on 2005-04-20
3
Medium Priority
?
424 Views
Last Modified: 2010-04-07
I want to fill a dropdown list with the contents of a HashTable:

<script runat="server">
colGroupType = New HashTable()
colGroupType.Add( "1", "Individual" )
colGroupType.Add( "2", "Couple" )
colGroupType.Add( "3", "Family" )

dropGroupType.DataSource = colGroupType
dropGroupType.DataBind()
</script>

<asp:DropDownList ID="dropGroupType" runat="server"></asp:DropDownList>

However, when I view the page I get the following statement 3 times in the Dropdown list:

System.Collections.DictionaryEntry

What am I doing wrong
0
Comment
Question by:gilkesy
  • 2
3 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13826427
<script runat="server">
colGroupType = New HashTable()
colGroupType.Add( "1", "Individual" )
colGroupType.Add( "2", "Couple" )
colGroupType.Add( "3", "Family" )

dropGroupType.DataValueField = "Key"
dropGroupType.DataTextField = "Value"
dropGroupType.DataSource = colGroupType
dropGroupType.DataBind()
</script>

<asp:DropDownList ID="dropGroupType" runat="server"></asp:DropDownList>

or


<script runat="server">
colGroupType = New HashTable()
colGroupType.Add( "1", "Individual" )
colGroupType.Add( "2", "Couple" )
colGroupType.Add( "3", "Family" )

dropGroupType.DataSource = colGroupType
dropGroupType.DataBind()
</script>

<asp:DropDownList ID="dropGroupType" runat="server" DataValueField="Key" DataTextField="Value"></asp:DropDownList>
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 500 total points
ID: 13826447
You will notice that the order in which the items appear is not the order in which you added them... That is because the Hashtable implements its only internal algorithm to retrieve data in the fastest way possible.

If you want a sorted list,

use the SortedList object instead

Dim colGroupType As New SortedList()
....
0
 

Author Comment

by:gilkesy
ID: 13826501
Thank You. Thats Great.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

804 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question