使用 ASP.NET GridView 时,DataSource 和 DataSourceID 均定义错误
是的,我知道。可能重复的问题。
但在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>
我收到这样的错误:
DataSource 和 DataSourceID 都是 定义在“Grid_Goster”上。删除一个 定义。 描述:在执行期间发生未处理的异常。 执行当前的网络请求。 请查看堆栈跟踪以了解更多信息 有关错误及其位置的信息 它起源于代码。
异常详细信息:System.InvalidOperationException:两者
DataSource 和 DataSourceID 是 定义在“Grid_Goster”上。删除一个 定义。
来源错误:
执行期间生成未处理的异常
当前网络请求。信息 关于起源和地点 可以使用以下方式识别异常:
,并且在我的 .cs 文件中有这样的代码。
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
Grid_Goster.DataSource = dr;
Grid_Goster.Visible = true;
我认为这段代码工作正常。 我该如何解决这个 DataSource
和 DataSourceID
问题?
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_Goster'. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这是一个愚蠢的问题;但最好只是要求澄清一下。您是否在同一控件上同时指定了数据源对象(在代码后面)和 DatasourceID(在 ASPX 标记中)?我想当您尝试数据绑定时,由于数据源不明确,它不会工作。
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.
您的代码后面必须有手动绑定。删除手动绑定或 SQL 数据源。
There must be manual binding inside your code behind. Either remove the manual binding or the SQL datasource.