【发布时间】:2014-04-24 10:22:40
【问题描述】:
我有一个带有中继器的用户控件。最初在页面加载中,我有从数据库中获取数据并绑定到转发器的代码。我现在想在用户控件之外使用这个功能,这样我就可以在页面上拥有多个并让它们绑定到不同的数据。
我现在的代码是:
Imports System.ComponentModel
Public Class UpdateList
Inherits System.Web.UI.UserControl
Private m_dataSource As Object
<TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")> _
<Category("Data")> _
<DefaultValue(Nothing)> _
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
If Me.m_dataSource <> value Then
m_dataSource = value
tryDataBinding()
End If
End Set
End Property
Public ReadOnly Property UpdateCount As Integer
Get
Return m_UpdateCount
End Get
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub tryDataBinding()
rep_Updates.DataSource = Me.m_dataSource
rep_Updates.DataBind()
End Sub
End Class
我在<DefaultValue(Nothing)> 收到一条波浪线并收到错误:
重载解析失败,因为没有可访问的“新”最适合这些参数:
'Public Sub New(value As Boolean)':不是最具体的。
'Public Sub New(value As Byte)':不是最具体的。
'Public Sub New(value As Char)':不是最具体的。
这是什么意思?谢谢
更新
解决方法是将数据源的属性声明更改为...
Private m_dataSource As Object
Public Property DataSource() As Object
Get
Return Me.m_dataSource
End Get
Set(value As Object)
m_dataSource = value
tryDataBinding()
End Set
End Property
【问题讨论】:
-
至少在 WinForms 中 DefaultValue 属性 ctor 不能为 Nothing。由于它没有定义初始起始值,而是定义何时保留属性值的比较值 - 在这种情况下无论如何看起来都很微妙,只需删除该属性即可。
-
@Plutonix 谢谢...我将 sn-p 作为 c# - 只是将其转换并粘贴到我的代码中,没有发现 System.Windows.Forms... 删除 TypeConverter、Category 和 DefaultValue 就可以了.发布为答案,我会标记。
标签: vb.net data-binding user-controls