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

Discussion in 'ASP .Net' started by mark4asp, Mar 5, 2007.

  1. mark4asp

    mark4asp Guest

    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?
    mark4asp, Mar 5, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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?
    >
    Eliyahu Goldin, Mar 5, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lee
    Replies:
    1
    Views:
    478
    Victor Bazarov
    Nov 2, 2004
  2. Replies:
    2
    Views:
    388
  3. bloodsugarsuckerfish

    Hashtable in Cahe seems to have items removed

    bloodsugarsuckerfish, Mar 7, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    497
    Sergey Zyuzin
    Mar 7, 2008
  4. Chuck Insight

    Why are HashTable Items Not Unique ???

    Chuck Insight, Mar 14, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    145
    Chuck Insight
    Mar 14, 2005
  5. Replies:
    9
    Views:
    291
    Michal Kleczek
    May 27, 2013
Loading...

Share This Page