2011-01-26 2 views
2

예, 알고 있습니다. 가능한 공개 질문.DataSource 및 DataSourceID 모두 ASP.NET GridView를 사용하여 정의 된 오류입니다.

하지만 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> 

와 나는 다음과 같은 오류가 발생합니다 :

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.

소스 오류 :

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

그리고 내 .cs에서 코드는 다음과 같이이 파일.

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

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

이 코드가 올바르게 작동한다고 생각합니다. 어떻게하면 DataSourceDataSourceID 문제를 해결할 수 있습니까?

답변

3

어쩌면 이것은 바보 같은 질문입니다. 그러나 설명을 요구하는 것이 좋습니다. 동일한 컨트롤에서 데이터 소스 객체 (코드 뒤에 있음) DatasourceID (ASPX 마크 업에)를 모두 지정 하시겠습니까? Datasource 모호성으로 인해 Databind를 시도 할 때 작동하지 않는다고 생각합니다.

0

코드 뒤에 수동 바인딩이 있어야합니다. 수동 바인딩 또는 SQL 데이터 소스를 제거하십시오.