View Single Post
  #7 (permalink)  
Old February 20th, 2012, 10:17 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

I think you're confused about what the "index" is. The index in a drop down is the zero based sequential number of the item in the list. E.g., when rendered into this HTML:

<option value="6">Holland</option>
<option value="1">USA</option>

the index (accessible through the SelectedIndex of the DropDownList at the server) of the Holland item would be 0, and 1 for the US item. The value (SelectedValue) for these items would be 6 and 1 respectively.

After reading this entire thread, I think when you said "I get the index back from SelectedValue", my guess is that you meant you get back the value but wanted the name. E.g. for Holland you got back 6, but wanted Holland. However, by using the terms you were using, we thought you got back 0, but wanted 6.

Does that make sense? And is that indeed the case?

If so, what you want is the Text property of the SelectedItem. That would return Holland. So, ddlCountries.SelectedItem.Text.

The suggested change by irProject was not meant as a final change in your project; just some temporary change in your code that would help you discover this.


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; February 20th, 2012 at 10:29 PM..
The Following User Says Thank You to Imar For This Useful Post:
shariful (February 21st, 2012)