将 Dictionary(Integer, String) 绑定到 DropDownList 的 DataTextField 属性
我有一个 State 类定义如下:
Public Class State
Public Property StateId As Integer
Public Property Name As Dictionary(Of Integer, String)
End Class
Name(x) 包含不同语言的状态名称。
我从方法 StateManager.GetAllStates() 获取状态集合 我想将此集合绑定到 DropDownList。问题是 我找不到如何将 DataTextField 属性设置为 stateList.Name(1) 这是我所在州的英文名称。
Dim stateList As StateCollection = StateManager.GetAllStates()
Me.DataSource = stateList
Me.DataValueField = "StateId"
Me.DataTextField = "Name(1).Value" <-- Problem here
Me.DataBind()
有人有主意吗?
谢谢
I have a State class defined like this:
Public Class State
Public Property StateId As Integer
Public Property Name As Dictionary(Of Integer, String)
End Class
Name(x) contains the state name in different languages.
I get a collection of State from the method StateManager.GetAllStates()
and I want to bind this collection to a DropDownList. The problem is that
I can't find how to set the DataTextField property to let's say stateList.Name(1)
which is the english name of my state.
Dim stateList As StateCollection = StateManager.GetAllStates()
Me.DataSource = stateList
Me.DataValueField = "StateId"
Me.DataTextField = "Name(1).Value" <-- Problem here
Me.DataBind()
Anyone have an idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用数据源时,不能使用复杂的表达式来指定值。
创建一个源,您可以在其中提取所需的值:
When you use a data source, you can't use complex expressions to specify values.
Create a source where you extact the values that you need:
您是否尝试过而不是“Name(1).Value”:
Rather than "Name(1).Value", have you tried: