问题
I have a usercontrol with a repeater. Originally in page load I had code which grabbed data from the database and bound to the repeater. I now want to take this functionality outside of the usercontrol so that I can have more than one on the page and have them bind to different data.
My code now is:
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
I get a wavy line at <DefaultValue(Nothing)>
and get an error:
Overload resolution failed because no accessible 'New' is most specific for these arguments:
'Public Sub New(value As Boolean)': Not most specific.
'Public Sub New(value As Byte)': Not most specific.
'Public Sub New(value As Char)': Not most specific.
What does this mean? Thanks
UPDATE
The fix was to change the property declaration for datasource to...
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
回答1:
at least in WinForms the DefaultValue attribute ctor cant be Nothing
(there is no such definition in Object Browser). DefaultAttribute
doesnt define an initial starting value (in spite of the name), but the comparison value for when to persist a property value. This seems dubious anyway in the case of a webform and datasource, so just remove the attribute.
As you noted the TypeConverter
is probably out of place as well.
来源:https://stackoverflow.com/questions/23266178/overload-resolution-failed-because-no-accessible-new-is-most-specific-for-thes