0

我将尝试对此进行不同的处理,因为我的最后一次尝试并不清楚:

我运行了一个 SQL 查询并产生了以下结果:

在此处输入图像描述

我现在想构建一个向用户显示这些结果的 ASP.NET 页面

我正在尝试放置一个列表视图来显示用户,并在其中放置一个网格视图来显示用户拥有的项目。

到目前为止,我的代码如下所示:

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

但是,在运行此程序时,我收到以下错误:

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

任何人都可以对此有所了解吗?:)

更新

按照伊卡洛斯的建议,我现在有以下几点:

在此处输入图像描述

但是,它包含多个数据,我似乎无法将其压缩为 2 个用户,1 个有 2 个项目,另一个有 1 个项目。

4

1 回答 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">
于 2013-03-22T11:55:06.297 回答