我會嘗試做這個不同的看法是我最後一次嘗試wasnt明確:呈現和分組數據ASP.NET/SQL
我已經運行SQL查詢併產生以下結果:
現在我想建立一個顯示這些結果給用戶
我試圖將一個列表視圖顯示給用戶,而這裏面,一個gridview顯示的項目的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.
任何人都可以闡明這一些輕? :)
UPDATE
繼伊卡洛斯的建議,我現在有以下幾點:
但是,它包含多個數據,我似乎無法凝結這2個用戶,1個2個項目,另1個項目。
您能告訴我們您試圖獲得結果的SQL嗎? – Paul 2013-03-22 11:24:50
你在SQL查詢中使用Distinct嗎?我懷疑這個問題是,你試圖顯示的數據包括ID等等。將它們從要顯示的數據中刪除,這將允許你只創建唯一的條目(你可以使用Linq Distinct()) – Dave 2013-03-22 11:24:54
重構問題,對不起所有:) – Haden693 2013-03-22 11:50:36