Connecting Tech Pros Worldwide Forums | Help | Site Map

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

mark4asp
Guest
 
Posts: n/a
#1: Mar 5 '07
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[i].Value)
lblConsultantName.Text = ddlConsultant.Items[i].Text ;

Or is there an another way?


Eliyahu Goldin
Guest
 
Posts: n/a
#2: Mar 5 '07

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


lblConsultantName.Text =ddlConsultant.Items.FindByValue
(hidConsultantID.ToString()).Text;

Is it what you are after?

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"mark4asp" <mark4asp@gmail.comwrote in message
news:1173098639.637914.138990@30g2000cwc.googlegro ups.com...
Quote:
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[i].Value)
lblConsultantName.Text = ddlConsultant.Items[i].Text ;
>
Or is there an another way?
>

Closed Thread