DataSourceID of 'controlname' must be the ID of a control of type IDataSource.

When I use the following code, I get this error:

The DataSourceID of 'PSAnswersGridView' must be the ID of a control of type IDataSource.  A control with ID 'Key_Trait_Analysis_ObjectDataSource' could not be found.

I am trying to define an objectdatasource in code-behind and bind it to a gridview:

Partial Class Admin_Stuff

Inherits System.Web.UI.Page

Protected Key_Trait_Analysis_ObjectDataSource As ObjectDataSource

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
...
  Key_Trait_Analysis_ObjectDataSource = New ObjectDataSource
  Key_Trait_Analysis_ObjectDataSource.ID = "Key_Trait_Analysis_ObjectDataSource"
  Key_Trait_Analysis_ObjectDataSource.TypeName = "Key_Trait_Analysis"
  Key_Trait_Analysis_ObjectDataSource.SelectMethod = "Analyse"
..parameter setup..
PSAnswersGridView.DataSourceID = "Key_Trait_Analysis_ObjectDataSource"

GRidView is declaratively defined in the aspx:
                <asp:GridView ID="PSAnswersGridView" runat="server" Caption="Career Success Analysis"
                    CaptionAlign="Top" CssClass="admin" >
                    <EmptyDataTemplate>
                        --Nothing found--
                    </EmptyDataTemplate>
                </asp:GridView>

BUT!

If I declaratively define the objectdatasource in the aspx page and just refer to it in the code instead, I get no error and it works.

Partial Class Admin_Stuff

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
...
  Key_Trait_Analysis_ObjectDataSource.TypeName = "Key_Trait_Analysis"
  Key_Trait_Analysis_ObjectDataSource.SelectMethod = "Analyse"
..parameter setup..
PSAnswersGridView.DataSourceID = "Key_Trait_Analysis_ObjectDataSource"


In the aspx:

 <asp:ObjectDataSource ID="Key_Trait_Analysis_ObjectDataSource" runat="server"></asp:ObjectDataSource>  

 

Can anyone tell me why the former errors out and the latter works?

0
PhilM99
10/27/2006 6:09:06 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1104 Views

Similar Articles

[PageSpeed] 34
Get it on Google Play
Get it on Apple App Store

The DataSourceID is used for connecting statically defined items at the aspx page level.  If you're dynamically creating the ObjectDataSource then just assign it to the DataSource property of your GridView.  You don't need the ID in that case, plus it doesn't appear to work.
0
stiletto
10/27/2006 6:38:59 PM

Thanks for that. Ok that clears it up. I could swear that I tried it both ways. In the documentation it say that one cannot use BOTH Datasource and DatasourceID.

 So anyhow, I just tried it dynamically created with Datasource= and I do not get  the error! I do however get other errors. (Control not added to page... so I add it to the page). (Cannot locate parameters... etc.) It seems the declarative approach is simpler so I'm going with that. But I really wanted to know why one worked and not the other. Thanks!

0
PhilM99
10/27/2006 7:25:02 PM

Thanks! It worked for me too.

0
shivendradev
4/27/2009 4:32:51 PM
Reply:

Similar Artilces:

The DataSourceID of 'gv2' must be the ID of a control of type IDataSource. A control with ID 'objDs1' could not be found.
i have a radiobutton list and gridview and a object data source at runtime i'm changing the object data source by clicking on the radiobutton list selected index changed and here is my source code....          <asp:RadioButtonList runat="server" ID="rblView" RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="True" OnSelectedIndexChanged="rblView_SelectedIndexChanged">                &nb...

The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource. A control with ID 'AccessDataSource' could not be found.
what i'm missing that i get the error: The DataSourceID of 'GridView1' must be the ID of a control of type IDataSource.  A control with ID 'AccessDataSource' could not be found.      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="NewsId"                  EmptyDataText="There are no data records to display.">          &nb...

The DataSourceID of 'DetailsView1' must be the ID of a control of type IDataSource. A control with ID 'AccessDataSource1' could not be found.
 Anyone help with this? i have tried lots of ways to query this database and create the insert command, including making my own data sets and setting it up that way with my own custom SQL statement.....this did not work, so i though i would use VWD 2008's own tools to create the insert, i have been left with the following error: The DataSourceID of 'DetailsView1' must be the ID of a control of type IDataSource.  A control with ID 'AccessDataSource1' could not be found.   Everything looks ok to me. Code below:   <%@ Page Title="" Lan...

How do fix the error The DataSourceID of 'DataGrid1' must be the ID of a control of type IDataSource. A control with ID 'SqlMedTable' could not be found.
How do you fix the error: The DataSourceID of 'DataGrid1' must be the ID of a control of type IDataSource.  A control with ID 'SqlMedTable' could not be found.Here is the code.protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) {MedicalClassLibrary.Connection c = new MedicalClassLibrary.Connection(); c.GetMedicalTable();DataGrid1.AutoGenerateColumns = true; DataGrid1.DataSource = c.DS;InputDiv.Visible = false;Label1.Visible = false; txtRx.Focus(); } } Here is the class medhod:public void GetMedicalTable() {string medTable = "SELECT ...

The DataSourceID of 'ddlDevice' must be the ID of a control of type IDataSource. 'dsMain' is not an IDataSource.
I seem to be having trouble binding the objects in my page to the datasource. The subject line contains the error message that I keep receiving.  I am trying to bind a dropdownlist with my datasource.  I noticed that if I click on the droplist, go to the properties window and try to select a datasource; nothing is listed. Post the code for filling dsMainNC... How did you setup the datasrouce? I think you didnt use the wizard to connect into database. You will not see any datasrouce in the properties window till u use the wizard to (server explorer) create the databa...

The DataSourceID of '' must be the ID of a control of type IDataSource
I have a grid view with dropdown list. I have to be able to edit it by clicking on ‘Edit’ link button. Dropdown at this point should be populated with data.1. I need to display one of the values of the dropdown in the grid (read only). This value is what is coming to populate entire row of the grid view. Even I do not have an error on initial load of grid view and while debugging I see a data coming to populate grid view row and a dropdown, the column is empty. How can I populate a value of the grid view column of the row as a selected field of the dropdown? 2. I am getting an error when l...

Trying to load user control Dynamcially but getting error " Control 'ctl02_GridView1' of type 'GridView' must be placed inside a form tag with runat=server"
I am tired of this error and now writing a post.  My Web application has two pages. Page one has drop down list which redirect the page to another page . where I am going to load the usercontrol dynamically according to the choice of the user.     protected void ddlViewReport_SelectedIndexChanged(object sender, EventArgs e)  { if (ddlViewReport.SelectedIndex == 1) { Session["ReportType"] = ddlViewReport.SelectedIndex; Response.Redirect("RepReportingPage.aspx"); int crosspagevalue = ddlViewReport.SelectedIndex; } if (ddlViewReport.SelectedIndex == 2) {...

Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
Hi, I'm getting this error when trying to port an old Atlas Web App to use the latest bits - any help would be nice as to what controls I CAN extend - so if I can't use a DIV what then?: Server Error in '/GRintranets' Application. Extender control 'DragPanelExtender1' cannot extend 'divPaginaHTML'. Extender controls of type 'AjaxControlToolkit.DragPanelExtender' cannot extend controls of type 'System.Web.UI.HtmlControls.HtmlGenericControl'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informati...

Control 'WzdResults_GridView2' of type 'GridView' must be placed
inside a form tag with runat=server. " That is the error message I get when I try to export my gridview data in excel. Ok, here are the requirements: I have wizard control which has 4 steps, each presenting data in gridview after running some queries on SQL server based on dates given by user. I get data in the gridview fine. Now, I want to generate a report, either using reportviewer or placing that data in excel spreadsheet. I tried with reportviewer. In windows form it works fine, but I could not get it running in web application. Below is the code for reportviwer: ReportViewer1.Pro...

3.1 Parser Error: Could not load type or Multiple controls with the same ID 'ctr' were found. FindControl requires that controls have unique IDs.
I have about ten cusom modules on my local machine and everything worked for about two weeks. Today I created new skin object and uploaded it and now none of my modules work. I get either error Parser Error: Could not load type ..." or Multiple controls with the same ID 'ctr' were found. FindControl requires that controls have unique IDs depending on which page I look at. None of these pages used skin with a new skin object. Btw, I stripped skin object down to noting, no controls, no code and no changes to custom modules have been made. I wonder if  skin object update screwed ...

DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl
I have a Login Control inside a Panel that is inside a LoginView Control. LoginView Control (LoginView2)       |_  Panel (Panel1 )                 |_  Login Control (Login2)                                  |_    imageButton (LoginButton) I want to set the Panel.DefaultButton to the In...

The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl.
Hi, I am getting the following error when I set the default button of the panel in codebehind. The DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl. This is what I am doing.  In aspx <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  <asp:Panel ID="Panel1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/> ................... ................... ...

Control 'sdf' of type 'LinkButton' must be placed inside a form tag with runat=server.
 This is the code in the aspx file.<%@ Page Language="vb" AutoEventWireup="false" Inherits="WebFileManager._default" CodeFile="ISfilemanager.aspx.vb" %> <html> <head> <title>Kharafi National eDistribution <%=CurrentWebPath%> </title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="author" content="Osama Abu Mansour" /> <meta name="keywords" content="Kharafi eDistribution" /> <meta name="...

Control 'gv' of type 'GridView' must be placed inside a form tag with runat=server.
I got an error when i am trying to Render GridView using HtmlTextWriter  Please help me... Code is as below:public void d() {string a = ConfigurationManager.ConnectionStrings["NetWorldConnectionString"].ConnectionString; conn = new SqlConnection(a);cmd = new SqlCommand(); cmd.Connection = conn;cmd.CommandText = "StoredProcedure1";cmd.CommandType = CommandType.StoredProcedure; conn.Open();SqlDataReader rs = null; rs = cmd.ExecuteReader(); conn.Close();DataTable dt = new DataTable();DataSet ds = new DataSet(); dt.Load(rs); gv.DataSource = dt;   g...

Web resources about - DataSourceID of 'controlname' must be the ID of a control of type IDataSource. - asp.net.presentation-controls

Resources last updated: 12/25/2015 2:31:05 AM