• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

ASP.net VB.net Add ID value in addition to Item DropDownList

Hi

In ASP.net I add text items to a DropDownList. For each of these I also want to store an ID
so that when the user selects the item the app uses the ID and not the text item.

Thanks
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
Daniel Van Der WerkenIndependent ConsultantCommented:
This might not be the most efficient way to do what you're asking about. But, in the past, this is what I've done for something similar.

What I've done is create a Dictionary or Hashtable that contains the ID as the key and the text value for the item as the value. So,

I then store those and at the same time, I add the text string values to the drop down list.

Then, when the DD List item is selected, I ask the Dictionary or Hashtable to give me the key ID for that text value. I now have a way to reverse out the ID from the text.

Otherwise, I'm not sure if this is easily done. You could possibly tie the ID to the index in the DD List, but that might not work if your ID's are like 12098 and your index is 3.

As far as I know though, the items for DD Lists can be objects but are not strongly typed. The only other possible way I can think of doing this would be to subclass the DD List and have the item be a type of Dictionary or such and reverse it though that way once the selection is made.

I
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now