我有一份工作可以顯示圖像中給出的用戶列表。我想知道ASP.NET中的哪個數據控件對於這種情況是完美的。我只是在玩Listview,但我想從這裏的人們獲得輸入。謝謝。 Faraaz。
Update1:我應該在這裏使用gridviews列表(嵌套在列表視圖中)嗎?或者可以用單個列表視圖來完成?
我有一份工作可以顯示圖像中給出的用戶列表。我想知道ASP.NET中的哪個數據控件對於這種情況是完美的。我只是在玩Listview,但我想從這裏的人們獲得輸入。謝謝。 Faraaz。
Update1:我應該在這裏使用gridviews列表(嵌套在列表視圖中)嗎?或者可以用單個列表視圖來完成?
顯然不宜使用,網格視圖會給你想要的表格佈局(可能與自動生成的列最小的努力)。
但是,如果分頁,排序,編輯需要注意,那麼我寧願使用Repeater控制。主要原因是精確控制加價。例如,網格視圖不支持諸如<colgroup>
或<thead>
等元素(同樣,這些元素可能不需要用於您的佈局)。如果需要分頁/排序/編輯等,那麼ListView是更好的選擇。只要顯示多個表格,就可以使用嵌套控件 - 例如,嵌套網格視圖的中繼器/列表視圖。
編輯:
你是不是對你有和數據的結構非常清晰也有關,你想要的確切佈局。所以這是我的假設 - 你有一個單獨的List<Subscriber>
包含根用戶和他們的孩子。在佈局中,您需要一個用於root用戶的表格,後面是多個表格 - 每個根用戶的子項都有一個表格。
馬克 - 起來會像
<asp:Repeater runat="server" ID="Outer" >
<HeaderTemplate>
<%-- Put a grid here for parent -->
<asp:GridView runat="server" ID="Root" DataSource='<%# GetRootSubscribers() %>' >
... column def etc
</asp:GridView>
</HeaderTemplate>
<ItemTemplate>
<!-- Put a grid here for children for current root subsriber -->
<asp:GridView runat="server" ID="Child" DataSource='<%# GetChildSubscribers(Eval("MemberID")) %>' >
... column def etc
</asp:GridView>
</ItemTemplate>
</asp:Repeater>
這兩個代碼隱藏的方法,如
protected IEnumerable<Subscriber> GetRootSubscribers()
{
// I am not sure how you decide if a subscriber is a parent or not, I have just
// illustrated a condition where you have a parent id field to indicate the same
return allSubscribers.Where(s => s.ParentID == null);
}
protected IEnumerable<Subscriber> GetChildSubscribers(object memberId)
{
// I am not sure how you decide a child subscriber, I have just
// illustrated a condition where you have a parent id field to indicate the same
return allSubscribers.Where(s => s.ParentID.Equals(memberId));
}
// bind the outer repeater to root list
Outer.DataSource = GetRootSubscribers();
Outer.DataBind();
希望這會給你如何進行一些想法的支持。
對我來說,這是一個帶有常見標題文本的GridView。您可以在網格之前使用任何其他控件或純HTML製作上面的第一個條。列表視圖不網格和在我看來,當最終預期的結果是更接近電網
嘿感謝您的快速響應。但在我的情況下,我必須顯示GridView的列表(根據用戶可以擁有的子用戶數量,這個計數是動態的)。請指教。 – nfa379
看看GridView控件。此外,檢查了這一點(http://stackoverflow.com/questions/891918/grid-view-vs-list-view)比較兩個控件。 – AlexB