Very Easy Dropdownlist Problem

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

Hi Everyone,

How do you get two or more listitems to have the same value?



I am trying to do this:

<asp:dropdownlist id="one" runat="server">
<asp:listitem text="hello" value="hi" />
<asp:listitem text="yada" value="hi" />
<asp:listitem text="NO" value="die" />
</asp:dropdownlist>

If I select "yada", and submit the page, the page reloads by "hello" will be
selected. It happens whenever I want
two or more listitems to have the same values but differen't text. I am
doing this for an email alert kind of system..



The purpose of this program is to let a user select a product that they are
interested in. There are managers for the products.. When the user submits
the form, it will send an email the manager (who's email should be populated
in the 'value'). However, there is more than one product that each manager
is in charge of.
 
M

MattC

Luis,

Your problem is probably due to the way ASP.NET reloads the viewstate info.
I think it sets the selected index using the Items.FindByValue() method.
This means that the first one it comes to that matches is hello.

My only suggestion at this point without looking to deep into it, is to
create a user control containing your dropdown but that repopulates when it
loads using FindByText instead, manky but all i can think of right now.

MattC
 
C

Curt_C [MVP]

in the Page_Load check for IsPostBack and iterate through the dropdownlist,
by text instead of value
 
C

Curt_C [MVP]

Oh... And with the massive number of posts you've put up I suggest you start
to use Google, or whatever search engine you like. Most of these issues are
easily found...
 
P

Patrice

See the other thread for things that works...

Now I would rather consider that " value" shoudl be the unique id for the
corresponding text.

I would do this this way (granted more complicated but likely more general)
:
- the text is the product description, the valuie is the product id
(unique).

You know then server side by its id whic product where selected allowing to
get the correspoing managed and whatever else information you would need to
create the mail...

Patrice
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top