ASP.NET Dropdownlist BUG???

  • Thread starter Thread starter Jason Dean
  • Start date Start date
J

Jason Dean

Hello,

I'm using an ASP.NET dropdown list on my company's "Contact Us" page to
direct certain subjects of emails to different email addresses. The user
selects the subject from a dropdown list, then their email is routed to the
proper person. My code is like this:

<option value="">Select a Topic</option>
<option [email protected]>UserID/Password</option>
<option value="(e-mail address removed)">Technical Support</option>
<option value="(e-mail address removed)">Personal Training </option>
<option value="(e-mail address removed)">Become a Club</option>
<option value="(e-mail address removed)">Question for the
Faculty</option>
<option [email protected]>Systems</option>

As you can see the value on some of the options is the same. This is
because some subjects go to the same email addresses. My problem is that
when I try to retrieve the "SelectedItem.Text" in my code-behind, it grabs
the text of the first option in the list this that value. So if i selected
"Personal Training" in the example above, the SelectedItem.Text would be
"Technical Support". Is there anyway around this problem.

Thanks a bunch

-Jason
 
create an array of email addresses in your codebehind, and use the index of
the item in the array instead of the actual email address. Then, when your
page posts back, you look up the real email address from the array using the
value.



--
Pete
====
Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 
Pete,

Thanks so much for your reply. The dropdownlist is actually being populated
being populated by an xml doc right now. I use the DataBind method to fill
the list. Will your suggestion still work?

My XML looks like this:

<item>

<topic>General Help</topic>

<contactperson>[email protected]</contactperson>

</item>

<item>

<topic>Services</topic>

<contactperson>[email protected]</contactperson>

</item>

-Jason
 
Jason said:
Hello,

I'm using an ASP.NET dropdown list on my company's "Contact Us" page to
direct certain subjects of emails to different email addresses. The user
selects the subject from a dropdown list, then their email is routed to the
proper person. My code is like this:

<option value="">Select a Topic</option>
<option [email protected]>UserID/Password</option>
<option value="(e-mail address removed)">Technical Support</option>
<option value="(e-mail address removed)">Personal Training </option>
<option value="(e-mail address removed)">Become a Club</option>
<option value="(e-mail address removed)">Question for the
Faculty</option>
<option [email protected]>Systems</option>

As you can see the value on some of the options is the same. This is
because some subjects go to the same email addresses. My problem is that
when I try to retrieve the "SelectedItem.Text" in my code-behind, it grabs
the text of the first option in the list this that value. So if i selected
"Personal Training" in the example above, the SelectedItem.Text would be
"Technical Support". Is there anyway around this problem.

Thanks a bunch

-Jason

Remember, asp.net only works on the server. The browser sees
a regular <select> element. When you (the user) selects one
option, then just the selected value is returned to the
server. asp.net has no way to know if this was the first or
second occurrence of this value.
 
While not necessarily elegant, you could always use a simple cheat. When the
list is generated from a dataset you could walk the rows (for each construct
works well) and pop a unique prefix on each value. For example, using the
row ordinal, you could create the following values:

[email protected]
[email protected]
etc.

Then, when the post occurs, simply split the value and discard the first
element of the array on the tilde (or another character you know is safe).
The second element contains your formed email address, and you'll always
have a unique selection to return the correct Text property.

F Buchan
 

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

Back
Top