Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 619281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:38:15+00:00 2026-05-13T18:38:15+00:00

I am trying to create a custom datasource control. I have been following this

  • 0

I am trying to create a custom datasource control.

I have been following this article to the letter (I think…).

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 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

Any help or suggestions will be very much appreciated.

Continued…

Looking at the stack trace shows that the error originates at:
System.Web.UI.WebControls.DataBoundControl.GetDataSource().

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 FindControl part is succeeding but that the source = control as IDataSource; leaves source as a null value, i.e. the conversion fails – But Why?

protected virtual IDataSource GetDataSource()
{
    if ((!base.DesignMode && this._currentDataSourceValid) && (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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:38:15+00:00Added an answer on May 13, 2026 at 6:38 pm

    Thank you epitka, the problem was caused by the control not being registered on the page correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom control - a button - which will have
I've been trying to create a custom control that works exactly like the Panel
I have a custom content type with custom fields. I'm trying to create a
I'm trying to create a custom JSP tag that would take an array object
I am trying to create a custom accordion for my page to that display
I'm trying to create a custom transition, to serve as a replacement for a
I am trying to create a delegate protocol for a custom UIView. Here is
I'm trying follow a tutorial to create a custom USB driver in Linux and
I'm trying to create with Delphi a component inherited from TLabel, with some custom
I have been following the following post on using multiple ItemTemplates in a ListView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.