.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

I have a gridview defined in my aspx page having a DataSourceID="myDataSourceID".  I have a <asp:SqlDataSource ID="myDataSourceID ...</asp:SqlDataSource> on the same page.  The first time a user comes onto the page that is the datasource I want to use to load the gridview...I works no problems.

I also have some check boxes on the page in a CheckBoxList with OnSelectedIndexChanged="myCodeBehind".  In myCodeBehind I build a query using the values of the checkboxes (thanks akhhttar) and try to use the query in to bind data to the gridview...

        Dim SqlDataSource1 As New SqlDataSource
        SqlDataSource1.ConnectionString = "$ ConnectionStrings:startpagegridview1ConnectionString"
        SqlDataSource1.ProviderName = "$ ConnectionStrings:startpagegridview1ConnectionString.ProviderName"
        SqlDataSource1.SelectCommand = Query
        GridView1.DataSource = SqlDataSource1

Site builds and publishes ok, but at runtime...


Server Error in '/' Application.

Both DataSource and DataSourceI

View Complete Post

More Related Resource Links

Both DataSource and DataSourceID are defined on 'ddlEvent'. Remove one definition


 Hi I have encountered the above error. I have read a couple of solution in this fourm and was not able to resolve it. here is my code

This page is called on load, to populate combo boxes of  the page.  when I comment this method, I am able to run the page, but when I uncomment the method, I get the above error.


I have search on both      ......  DataSource     and     DataSourceID  and was not able to find any code in my application to proof that I am using them in the apsx page ( front page ).  I only can see in the code behind like this method. .

One of the solution is to remove either one, but how can I remove when I do not see any in the front page. ( apsx )

please advise.


        private void Combo_Bind()
                ddlEvent.DataSource = select("usp_dbo_ASL_JV_Template_JVTemplateName_SELECT");


Bogus DataSource, DataSourceID Error Message

I believe this may be a bug in the .NET runtime or perhaps in LINQ2SQL, but I am not sure where or how to report it? Can anyone help me? I have a simple C# web page that is using a gridview to display an email log. The grid is bound in the code behind to a LINQ2SQL query and there are no parameters set for the DataSource, or the DataSourceID in the gridview in the .aspx page. This page works fine in Visual Studio 2010. Compiles, runs with no errors or warnings. When we publish it to a server with IIS 6.0, it displays the following error: "Both DataSource and DataSourceID are defined on 'gridview1'.  Remove one definition"  The solution is to set  "grdVendorEmailLogs.DataSourceID = string.Empty;"  But why when there is no DataSourceID declared or set to begin with? Here is the gridview code:  <asp:GridView ID="grdVendorEmailLogs" runat="server" AutoGenerateColumns="false"                    Width="80%" CssClass="gvHeaderRow" Font-Names="Verdana" Font-Size="Small">                    <Columns>  &n

Have templatefield in edit mode and datasource defined in code behind

Is this possible? Some sample code:<asp:GridView ID="gvConcerns" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:TemplateField HeaderText="Number" Visible="true" SortExpression="Number"> <EditItemTemplate> <asp:Label ID="lblEditNo" runat="server" Text='<%# Eval("number") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Part" Visible="true" SortExpression="part"> <EditItemTemplate> <asp:Label ID="lblEditPart" runat="server" Text='<%# Eval("part") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="List" Visib

How can I remove/hide built-in Title field in list definition

Now I'm customize a new Content and then new List Template, just like below definition;  <ContentType ID="0x0100ed096ab35eeb4d2e98fb71b9842e9616" Name="Staff Member" Group="Berry Gardens Internet">  <FieldRefs>   <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />   <FieldRef ID="{F5E777EA-C083-4c2f-BC10-E4BF2B4D6372}" Name="Synopsis" />   <FieldRef ID="{2307576C-A060-4c2d-BABC-34E5A9924667}" Name="Image" />   <FieldRef ID="{051B830A-8105-4384-9AA1-103CEE43B760}" Name="Email Address" />  </FieldRefs> </ContentType> It is inherit from Item parent type, and using built-in Title field({fa564e0f-0c70-4ab9-b863-0177e6ddd247}), but I found that it's diffcult to remove/hide it. When in the default list view, there are two Title fields. So what can I do in the list definition. Regards upzone    

how to remove a record from joined sql datasource?


hi there, 

im workingon a shopping cart project,

as it has three tables joined togather and i want to add a button on the showcart page to let user remove products that they don't want to buy,

here is the sql data source code and the repeater:

<asp:SqlDataSource ID="cartDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ShopDatabase %>" 
        SelectCommand="SELECT Carts.ID, CartItems.ProductId, CartItems.Quantity, Products.Name, Products.ImageUrl, Products.Price
FROM Carts
INNER JOIN CartItems ON Carts.ID = CartItems.CartId
INNER JOIN Products ON CartItems.ProductId = Products.ID WHERE (Carts.ID = @Id)">
                <asp:SessionParameter DefaultValue="0" Name="Id" SessionField="CartId" />
<asp:Repeater ID="cartRepeater" runat="server"
        DataSourceID="cartDataSource" OnItemCommand="Repeater1_ItemCommand" 

Hide a repeater in ASP.NET C# if the DataSource contains no items?

I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:
In the (C#) code-behind I'm basically using LINQ to pull a listing of information from an XML document and bind that information to the first repeater.

Searching for the answer to this, it seems the method is to determine whether the data for the nested repeater is empty. If it is, then you set the visibility of the repeater to false.

Manually sorting and paging Gridview without using datasource control

Many a times while working with Gridview we want to work with the paging and sorting functionality without using any datasource control. Gridview is flexible enough to perform these tasks without the use of any datasource control and only a few lines of code.

User Defined Functions in Microsoft SQL Server

User Defined Functions are compact pieces of Transact SQL code, which can accept parameters, and return either a value, or a table. They are saved as individual work units, and are created using standard SQL commands. Data transformation and reference value retrieval are common uses for functions. LEFT, the built in function for getting the left part of a string, and GETDATE, used for obtaining the current date and time, are two examples of function use. User Defined Functions enable the developer or DBA to create functions of their own, and save them inside SQL Server.

Remove #Region from whole web site


Hi All,

I need to deliver source code to client and my boss need to remove all the comments and #region sections from the whole web site source code.

So is there any functionality available in visual studio 2010 or may be in an other 3rd party tool available to do so, which can remove all the #region from all over the source code ?

Otherwise my developers has to do donkey work.... :(( and I don't wish it. 

Any help or tips/tricks would be appreciated.


Dynamic Data, Domain datasource, Poco and lookups


Mr. Edward,

Excuse my question but: it is necessary to involve in our projects something more than just Dynamic Data or should we make use of all other features available in VS2010 (which will make assume taht they had been left out of the Dynamic Data framework) like: wef, poco, azure, wcf, cloud, mvc, silverllight, ajax, odata, agile, workflow, etc.?

Sorry my ignorance, I'm just transcribing names as they come to my mind and of which I don't know anything about


Carlos Porras (El Salvador)

The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must



This is frustrating, and I don't know how to solve it.

I have a strange problem. I am adding a LinqDatasource object, and set the context:

        protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
            e.ObjectInstance = new KaruselaDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

Then I get this error:
The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.


On web.config I already have this:
<add assembly="System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

NOTE: The datacontext is in a different project (DLL proect) where I added a refernce to System.Data.Linq.

is there another way adding a refernce to a web project? or only though teh web.config?


How to write SQL Datasource programatically in VB


Can someone pls help me to rewrite this programatically!


<asp:SqlDataSource ID="DS" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [Products] WHERE ([ProductID] = @QSID)">
                    <asp:QueryStringParameter DefaultValue="" Name="QSID" QueryStringField="ID"
                        Type="Int32" />


Thank You in advance!


Configure Datasource using gridview problem


Hi i  have one asp.net textbox control..

and one dropdownlist inside gridview itemtemplate textbox..

what my problem..?

A Textbox36 has values some thing like this A1','A2','A3

i wirte this below query in sqldatasource1 and this sqldarasource1 is binded to gridview ItemTemplate Dropdownlist..

Select ItemName from Table1 where code in (@C)

Here @C im refering to Textbox36..

It show me the record if it has one value if its multiple like A1','A2','A3 it not showing/filtering ItemName data..

Whatz the probel?

Search for a string in my datasource dynamically


I am displaying an Rssfeed on my page by using XmlDataSource and Datalist controls.

I want the user to be able to limit the information that is returned to my datalist.  To do this I have a textbox on the form that allows the user to enter their search criteria.

I need to be able to dynamically create a query string utilizing the information that the user entered in the textbox.  I am also using a drop down list and allowing the user to select whether they want to search in the title, description, or all parts of the xml file.

I am having trouble figuring out how to reference the data contained in my textbox in my query string.  Where the query string says 'asp', I want to replace 'asp' with the content from my sSearch variable.  Can anyone tell me how to reference my variable in the query string???

string sSearch = txtSearch.Text;
        string SQuery = "";

        if (DropDownList2.SelectedIndex == 0)
            SQuery = "[contains(title), 'asp')]";

Composite Control which contains arbitrary content defined in .aspx of parent and thier ViewState


I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>

<div class="box">
    <div class="Header-Left">
        <div class="Header-Right">
            My Control
    <div class="Content">
        <asp:PlaceHolder ID="contentPlace" runat="Server" />

"Type ASP.x is not defined" error for dynamic user control when publishing updateable


I have a user control (ContainerCtrl) which programmatically instantiates another user control (SimpleCtrl) in OnLoad. It builds and runs fine, but when I publish it I get the error "error BC30002: Type 'ASP.SimpleCtrl' is not defined." (If I publish without the "updateable" option there's no error, but I need the site to be updateable.)

I assume this has to do with the particulars of how the assembly(ies) are built for the different compiler options. My question is, how can I get it to work properly for "updateable" publishing?

VS 2008 / .NET 3.5 sp1

The code follows (web.config is the default from Visual Studio).

Many thanks, Dave


<%@ Control Language="VB" ClassName="SimpleCtrl" CodeFile="SimpleCtrl.ascx.vb" Inherits="_SimpleCtrl" %>

    Simple control


Partial Class _SimpleCtrl
    Inherits UserControl

    'Nothing to see here.

End Class


<%@ Control Language="VB" CodeFile="ContainerCtrl.ascx.vb" Inherits="_ContainerCtrl"

Web deployment project - web.config section replacement does not add remove tag


I have a web application that is actually installed as a component of a third party site.  In some configurations, I need to remove certain connection strings and re-add them.  I'm replacing this web.config section with a xml file that includes the following:

      <remove name="MyOverridenConnection"/>
      <add connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDb;Data Source=MyServer" name="MyOverridenConnection"

For some reason the remove tag is left out during the substitution and I end up with the following in the installed config:

      <add connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDb;Data Source=MyServer" name="MyOverridenConnection"

Is there any way to issue removes in replaced sec

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend