我在 page_load 中有一个下拉列表填充其中的值列表。
我想选择一个特定的值
Me.DropDownList_LocalOfficeAssignment.SelectedValue = ct.LocalOfficeName
Me.DropDownList_LocalOfficeAssignment has list of values.
问题是:它总是指向第一项。
我试过这个
For Each item As ListItem In Me.DropDownList_LocalOfficeAssignment.Items
If item.Equals(ct.LocalOfficeName) Then
item.Selected = True
Exit For
End If
Next
DV.Dispose()
仍然指向第一项。我调试过,它应该指向最后一项。ct.localoffice 包含列表中的最后一项。这就是我填充下拉列表的方式:
Dim DV As DataView = New DataView(CacheVariable.States.Tables(0))
Dim DRV As DataRowView
Me.DropDownList_LocalOfficeAssignment.Items.Clear()
DV = New DataView(CacheVariable.LocalOffice.Tables(0))
If DV.Count > 0 Then
For Each DRV In DV
Me.DropDownList_LocalOfficeAssignment.Items.Add(New ListItem(DRV("Name"), DRV("LocalOfficeID").ToString))
Next
End If