Bound Dropdownlist & Hash Table

Results 1 to 2 of 2

Thread: Bound Dropdownlist & Hash Table

  1. #1
    Join Date
    Dec 1969

    Default Bound Dropdownlist & Hash Table

    Hi Guys,<BR><BR>I was originally using an Array but for the following problem but then i needed to have a different value for the dropdownlist options than what was displayed, so i changed to the following code:<BR><BR>-------<BR> Dim tabTitle as New HashTable(7)<BR> tabTitle.Add ("- Select a Title -","")<BR> tabTitle.Add ("Mr","Mr")<BR> tabTitle.Add ("Ms","Ms")<BR> tabTitle.Add ("Prof","Prof")<BR> tabTitle.Add ("Dr","Dr")<BR> tabTitle.Add ("Hon","Hon")<BR> tabTitle.Add ("Adv","Adv")<BR> selTitle.DataSource = tabTitle<BR> selTitle.DataValueField = "Value"<BR> selTitle.DataTextField = "Key"<BR> selTitle.Databind()<BR>-------<BR><BR>Now the problem is that a Hash Table is supposed to be unordered and for that reason the drop down list does not display the items in the above order, with the "select a title" option being at item number two and it therefore obviously looks pretty stupid when the registration form&#039;s default selected item is "mr" and the "select title" is in the middle of the list. Is there any other list/collection that i can use that will allow me to bind it to a control? I could use a dataset from a database but the above information really and most other drop down lists really do not need the information to be extracted from a database...<BR><BR>I tried setting the selectedindex so that the select a title would be shown, but then there are still items above it and below it in the list. Anyways i want it in the order of how i have coded it into my collection!!!!<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Use a sorted list

    Try useing a sorted List <BR>the sorting is based on the Key<BR>Ref page 389 of WROX Beginning ASP.NET<BR><BR> Dim fvDDLSO As New SortedList()<BR> fvDDLSO.Add("", "- select a title -")<BR> fvDDLSO.Add("bb", "oracle")<BR> fvDDLSO.Add("cc", "informix")<BR> fvDDLSO.Add("dd", "access")<BR> fvDDLSO.Add("ee", "eeeemic")<BR> fvDDLSO.Add("ff", "fffore")<BR> fvDDLSO.Add("gg", "ggginx")<BR> fvDDLSO.Add("hh", "hhhass")<BR> fvDDLSO.Add("kk", "kkkkss")<BR> Return Getlistbox(fvLINECNT, fvBOXNM, fvEDITVAL, fvDDLSO, fvDEFVAL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts