Is it possible to treat values and items of a DropDownList like a HashTable?

M

mark4asp

Is it possible to treat values and items of a DropDownList like a
HashTable?

My page records the value of the ConsultantName in a label
lblConsultant and the ID in a hidden field hidConsultantID

If I know the value of the ID: hidConsultantID, how do I lookup the
corresponding name, given that I have a DropDownList which maps
corresponding ConsultantIDs to their Names for the consultant
(ddlConsultant, IDs are values and names are shown as text)?

Must I need to loop through each item?

for (int i = 0; i < ddlConsultant.Items.Count; i++)
if (hidConsultantID.ToString() == ddlConsultant.Items.Value)
lblConsultantName.Text = ddlConsultant.Items.Text ;

Or is there an another way?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top