【问题标题】:How do I a preselect an item in a List(Of SelectListItem) for DropDownList in ASP.NET MVC VB.NET如何在 ASP.NET MVC VB.NET 中为 DropDownList 预选 List(Of SelectListItem) 中的项目
【发布时间】:2010-01-11 09:20:25
【问题描述】:

我有一个 List(Of SelectListItem),我用 NativeName 作为 .Text 和两个字母的 ISO 区域名称作为 .Value 填充它。

Dim countryList As IList(Of System.Globalization.RegionInfo) = GetRegionInfosForEuOnly() 将 dropDownCountryList 调暗为新列表(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>

现在我想将德国的 RegionInfo 设置为 DropDownList 中的预选项目。 但是

dropDownCountryList.Item(4).Selected = True

不起作用。

有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc drop-down-menu


    【解决方案1】:

    SelectList类的使用怎么样?

    【讨论】:

      【解决方案2】:

      我确定一个 selectlistItem 也有一个选定的值,所以你应该能够设置它

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多