0

I am getting following error and I can't resolve it.

<%@ 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>

This is my .aspx code

 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

This is my .aspx.vb code.I am just calling stored proc from function SelectToppersOfMonth1

and my select query in stored procedure is

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

I am getting error

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 Answers 2

2

just remove this from the page markup: DataKeyNames="ID" because your query is not returning any ID column and that breaks the binding. Or modify your SQL query to return also the ID column.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much.. I am newbie in asp.net i dont even know meaning of DataKeyNames i just copy pasted it from other gridview.. :D
0

You reference ID in the DataKeyNames property and it's not in your sql query. Is it normal?

2 Comments

he is not binding the ID in/to the header; he is trying to set ID as DataKeyName so the grid is aware of which column is PK in the bound data.
I was editing my answer then I saw your comment... you've been too fast

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.