views:

56

answers:

2

I have a List(Of SelectListItem) and I fill it with NativeName as .Text and the two letter ISO region name as .Value.

Dim countryList As IList(Of System.Globalization.RegionInfo) = GetRegionInfosForEuOnly() Dim dropDownCountryList As New List(Of SelectListItem)

For i As Integer = 0 To countryList.Count - 1
  dropDownCountryList.Add(New SelectListItem() With {.Text = countryList(i).NativeName, .Value = countryList(i).TwoLetterISORegionName})
Next

...

<td>
      <%=Html.DropDownList(customerType & "CountryCode", dropDownCountryList)%>*
      <%=Html.ValidationMessage(customerType & "CountryCode")%>
</td>

Now I want to set the RegionInfo for Germany as the preselected Item in the DropDownList. But

dropDownCountryList.Item(4).Selected = True

doesn't work.

Any Ideas?

+1  A: 

How about the use of the SelectList class?

takepara
A: 

A selectlistItem has a selected value as well I'm sure so you should be able to set that

if(language == german)
{
dropDownCountryList.Add(New SelectListItem() With {.Text = countryList(i).NativeName, .Value = countryList(i).TwoLetterISORegionName, .Selected = true})
}
Israfel