2011-12-09 2 views
0

다음 오류가 발생하며 해결할 수 없습니다.vb를 사용하여 asp.net의 gridview에 데이터를 바인딩하는 동안 오류가 발생했습니다.

<%@ Page Language="VB" MasterPageFile ="~/Master.master" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> 
<asp:GridView ID="GridView1" PageSize ="50" runat="server" AllowPaging="True" AllowSorting="True" 
      AutoGenerateColumns="False" DataKeyNames="ID"> 
     <Columns> 
      <asp:TemplateField HeaderText="ID"> 
       <ItemTemplate> 
        <%# Container.DataItemIndex + 1 %> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:BoundField DataField="Dname" HeaderText="Player" SortExpression="Dname" /> 
      <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> 
      <asp:BoundField DataField="GTScore" HeaderText="Score" 
       SortExpression="GTScore" /> 
      </Columns> 
     </asp:GridView> 
</asp:Content> 

이이 내 .aspx.vb의 code.I 단지 기능 SelectToppersOfMonth1

및 저장 프로 시저 내 선택 쿼리입니다에서 저장된 프로 시저를 호출하고 내에서 .aspx 코드

Partial Class test 
Inherits System.Web.UI.Page 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles  Me.Load 
    Dim fDate As Date = New Date(Today.Year, Today.Month, 1) 
    Dim tDate As Date = New Date(Today.Year, Today.Month, Date.DaysInMonth(Today.Year, Today.Month)) 
    GridView1.DataSource = Game.SelectToppersOfMonth1(fDate, tDate) 
    GridView1.DataBind() 
End Sub 
End Class 

입니다

SELECT TOP 100 A.[dispName] as [Dname], A.[city] as [City], SUM(B.[score]) as [GTScore] 

FROM [Players] A,[Games] B 

WHERE A.[ID]=B.[playerID] AND B.[startedOn] BETWEEN @fromDate AND @toDate 

GROUP BY A.[dispName], A.[city] ORDER BY [GTScore] DESC 

나는 오류

,369 무엇입니까
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'. 
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.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'. 

답변

2

쿼리가 ID 열을 반환하지 않고 바인딩이 끊어 지므로이 태그를 페이지 마크 업에서 DataKeyNames="ID"과 같이 제거하면됩니다. 또는 ID 열을 반환하도록 SQL 쿼리를 수정하십시오.

+0

대단히 고마워. 나는 asp.net에서 초보자이다. 나는 DataKeyNames의 의미를 알고있다. 나는 다른 gridview에서 그것을 붙여 넣었다. : D –

0

DataKeyNames 속성에서 참조하는 ID가 사용자의 SQL 쿼리에 없습니다. 정상입니까?

+0

그는 헤더의 /에 ID를 바인딩하지 않습니다. 그는 DataKeyName으로 ID를 설정하여 바운드 데이터에서 어떤 열이 PK인지 알 수 있도록합니다. –

+0

나는 내 대답을 편집했다. 나는 너의 의견을 보았다. 너 너무 빨랐다. – lnu

관련 문제