0

I'm going to try and do a different take on this as my last attempt wasnt clear:

I have run an SQL query and produced the following results:

enter image description here

I now want to build an ASP.NET page that displays these results to the user

I am trying to place a listview to show the user, and inside this, a gridview to display the items the user has.

So far my code looks like this:

 <asp:ListView ID="lvPersonItems" runat="server"  DataSourceID="sdsResults"  GroupItemCount="3"  EnableViewState="true" GroupPlaceholderID="groupPlaceHolder" ItemPlaceholderID="itemPlaceHolder">

 <LayoutTemplate>
 <table>
 <tr>
 <td>
 <table cellpadding="15">
 <asp:PlaceHolder ID="groupPlaceHolder" runat="server" />
 </table>
 </td>
 </tr>
 </table>
 </LayoutTemplate>

 <GroupTemplate>
    <tr>
    <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
    </tr>
 </GroupTemplate>

 <ItemTemplate >
 <td>
 <h3><%# Eval("Forename")%> <%# Eval("Surname")%></h3>

 <asp:GridView BorderStyle="None" ID="gvItems" AutoGenerateColumns="false" runat="server" DataSource='<%# Eval("Description") %>'>

 <Columns>
 <asp:BoundField DataField="Description" HeaderText="Description" />
 </Columns>

 </asp:GridView>

 <EmptyDataTemplate>
 <div style="background-color:Gray">No orders exists!</div>
 </EmptyDataTemplate>

 </td>
  </ItemTemplate>
 </asp:ListView>

  <asp:SqlDataSource ID="sdsResults" runat="server" 
          ConnectionString="<%$ ConnectionStrings:conString %>" 
          SelectCommand="sp_Test_Proc" SelectCommandType="StoredProcedure">
        </asp:SqlDataSource>

However, upon running this, I am getting the following error:

A field or property with the name 'Description' was not found on the selected data source.

Can anybody shed some light on this? :)

UPDATE

Following Icarus's advice, I now have the following:

enter image description here

However, it contains multiple data , I can't seem to condense this to 2 users, 1 with 2 items and another with 1 item.

3
  • Can you show us the SQL you tried to get the result, please? Commented Mar 22, 2013 at 11:24
  • Are you using Distinct in your SQL query? I would suspect the issue is, the data your trying to display includes the ID's etc. Remove them from the data to be displayed, this will then allow you to create unique entries only (where you could use Linq Distinct()) Commented Mar 22, 2013 at 11:24
  • Restructured the question, sorry all :) Commented Mar 22, 2013 at 11:50

1 Answer 1

1

Your problem is here:

 <asp:GridView BorderStyle="None" ID="gvItems" 
  AutoGenerateColumns="false" runat="server" 
  DataSource='<%# Eval("Description") %>'> 

Note that you are trying to Bind the property Description as the DataSource to the GridView.

The Datasource should be instead the SQL Data Source that you have defined further down; therefore change it to:

 <asp:GridView BorderStyle="None" ID="gvItems" 
 AutoGenerateColumns="false" runat="server" DataSource="sdsResults">
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's helped a bit, I've updated my question to reflect this, thanks!

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.