开发者

Both DataSource and DataSourceID are defined error using with ASP.NET GridView

Yes, i know. Possible dublicate question.

But it's different situation on gridview.

<asp:GridView ID="Grid_Goster" runat="server" AutoGenerateColumns="False" CellPadding="4" 
            DataSourceID="SqlDataSource3" ForeColor="#333333" GridLines="None" 
            Height="144px" Width="316px">

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SqlServerCstr %>" 
            SelectCommand="SELECT * FROM [AVUKAT]"></asp:SqlDataSource>

And i get error like this:

Both DataSource and DataSourceID are defined on 'Grid_Goste开发者_开发问答r'. Remove one definition. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Both

DataSource and DataSourceID are defined on 'Grid_Goster'. Remove one definition.

Source Error:

An unhandled exception was generated during the execution of the

current web request. Information regarding the origin and location of the exception can be identified using

And in my .cs file there is code like this.

SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Grid_Goster.DataSource = dr;
            Grid_Goster.Visible = true;

i think this code works correctly. How can i solve this DataSource and DataSourceID problem?


Maybe this is a dumb question; but it's good to ask just for clarification. Are you specifying both a datasource object (in your code behind) AND DatasourceID (in your ASPX markup) on the same control? I'd imagine that it wouldn't work when you try to Databind due to the Datasource ambiguity.


There must be manual binding inside your code behind. Either remove the manual binding or the SQL datasource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜