【问题标题】:DataTextField wont work when binding to List绑定到 List 时 DataTextField 不起作用
【发布时间】:2011-11-23 13:26:22
【问题描述】:
Public Class Item

    Public Text As String
    Public Value As Integer

End Class

Me.uxDropDown.DataSource = itms
Me.uxDropDown.DataTextField = "Text"
Me.uxDropDown.DataValueField = "Value"
Me.uxDropDown.DataBind()

为什么这不起作用,itms 是 List(Of Item)?

上线触发错误事件:Me.uxDropDown.DataBind()

DataBinding:“Project.Item”不包含名为“Text”的属性。

【问题讨论】:

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


    【解决方案1】:

    错误显然是“DataBinding:‘Item’不包含名为‘Text’的属性。”将这些公共变量改为公共属性,您的错误就会消失。

    Public Class Item
        Private _Text As String
        Private _Value As Integer
    
        Public Property Text() As String
            Get
                Return _Text
            End Get
            Set(ByVal value As String)
                _Text = value
            End Set
        End Property
    
        Public Property Value() As Integer
            Get
                Return _Value
            End Get
            Set(ByVal value As Integer)
                _Value = value
            End Set
        End Property
    End Class
    

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 2021-09-17
      • 2017-03-14
      • 2010-09-13
      • 1970-01-01
      • 2012-04-15
      • 2010-12-08
      • 2015-05-23
      相关资源
      最近更新 更多