Solved

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

Posted on 2016-10-25
2
72 Views
Last Modified: 2016-10-25
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
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 41858477
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
 

Author Closing Comment

by:Murray Brown
ID: 41858522
Thanks for the help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 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