从DataSourceControl继承不会产生IDataSource [英] Inheriting from DataSourceControl does not produce an IDataSource
问题描述
我正在尝试创建自定义数据源控件.
我一直在关注这封信(我认为...).
http://www.nikhilk.net/DataSourceControlBasics.aspx [
这对我来说似乎很奇怪,因为我的数据源继承自DataSourceControl,后者又实现了IDataSource.即使我在自定义数据源中显式实现IDataSource,也没有任何区别.
我的标记是:
I am trying to create a custom datasource control.
I have been following this article to the letter (I think...).
http://www.nikhilk.net/DataSourceControlBasics.aspx[^]
I have a skeleton / basic implementation of my datasource, however when I declare it in the markup and try to statically bind it to a gridview, I receive the following error:
The DataSourceID of ''grdVw'' must be the ID of a control of type IDataSource
This seems extremely strange to me, since my datasource inherits from DataSourceControl, which in turn implements IDataSource. Even if I explicitly implement IDataSource in my custom datasource, it makes no difference.
My Markup is:
<DataBrokerDataSource ID="objSrcDBroker" runat="server" />
<div>
<asp:GridView ID="grdVw" DataSourceID="objSrcDBroker" DataMember="Table0" runat="server">
</asp:GridView>
</div>
<div>
<asp:GridView id="grdVw2" DataSourceID="objSrcDBroker" DataMember="Table1" runat="server">
</asp:GridView>
</div>
我的控制权是:
And my control is:
Public Class CustomDataSource
Inherits DataSourceControl
Implements IDataSource 'Have tried with this statement included AND excluded = same result
Protected Overrides Function GetView(ByVal viewName As String) As System.Web.UI.DataSourceView Implements IDataSource.GetView
'Code here
End Function
Protected Overrides Function GetViewNames() As System.Collections.ICollection Implements IDataSource.GetViewNames
'Code here
End Function
End Class
我们将不胜感激.
Any help and suggestion will be very much appreciated.
推荐答案
我将数据源代码移至其他程序集并注册了该程序集,从而解决了该问题.尝试使用没有标签前缀的控件很愚蠢.
I moved the datasource code to a different assembly and registered the assembly and this fixed the problem. Trying to use the control without a tag prefix was silly.
这篇关于从DataSourceControl继承不会产生IDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!