title: Inheriting from DataSourceControl does not produce an IDataSource
body: <p>I am trying to create a custom datasource control.</p>
  
  <p>I have been following <a href="http://www.nikhilk.net/DataSourceControlBasics.aspx" rel="nofollow noreferrer">this article</a> to the letter (I think...).</p>
  
  <p>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:</p>
  
  <blockquote>
    <p><strong>The DataSourceID of 'grdVw' must be the ID of a control of type IDataSource</strong></p>
  </blockquote>
  
  <p>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.</p>
  
  <p>My Markup is:</p>
  
  <pre><code>&lt;DataBrokerDataSource  ID="objSrcDBroker" runat="server" /&gt;
  
  &lt;div&gt;
      &lt;asp:GridView ID="grdVw" DataSourceID="objSrcDBroker" DataMember="Table0" runat="server"&gt;
      &lt;/asp:GridView&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;asp:GridView id="grdVw2" DataSourceID="objSrcDBroker" DataMember="Table1" runat="server"&gt;
      &lt;/asp:GridView&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And my control is:</p>
  
  <pre><code>Public Class DataBrokerDataSource
      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
  </code></pre>
  
  <p>Any help or suggestions will be very much appreciated.</p>
  
  <p>Continued...</p>
  
  <p>Looking at the stack trace shows that the error originates at:
  <strong>System.Web.UI.WebControls.DataBoundControl.GetDataSource().</strong> </p>
  
  <p>I have examined this method in reflector (see below), looking at this (based on the error message that I am getting) it appears to me as though the <strong>FindControl</strong> part is succeeding but that the <strong>source = control as IDataSource;</strong> leaves <strong>source</strong> as a null value, i.e. the conversion fails - But Why?</p>
  
  <pre><code>protected virtual IDataSource GetDataSource()
  {
      if ((!base.DesignMode &amp;&amp; this._currentDataSourceValid) &amp;&amp; (this._currentDataSource != null))
      {
          return this._currentDataSource;
      }
      IDataSource source = null;
      string dataSourceID = this.DataSourceID;
      if (dataSourceID.Length != 0)
      {
          Control control = DataBoundControlHelper.FindControl(this, dataSourceID);
          if (control == null)
          {
              throw new HttpException(SR.GetString("DataControl_DataSourceDoesntExist", new object[] { this.ID, dataSourceID }));
          }
          source = control as IDataSource;
          if (source == null)
          {
              throw new HttpException(SR.GetString("DataControl_DataSourceIDMustBeDataControl", new object[] { this.ID, dataSourceID }));
          }
      }
      return source;
  }
  </code></pre>