2011-12-31 43 views
3

有沒有我可以在asp.net緊裹的CheckBoxList以便讓說,如果你的列表中有20個複選框任何方式,有10例的兩列:的CheckBoxList Asp.Net C#

Box     Box 
Box     Box 
Box     Box 
Box     Box 
Box     Box 
Box     Box 
Box     Box 
Box     Box 

我當前的代碼就是:

<asp:CheckBoxList ID="Numbers" runat="server" AutoPostBack = "true"> 
     <asp:ListItem> 1 </asp:ListItem> 
     <asp:ListItem> 2 </asp:ListItem> 
     <asp:ListItem> 3 </asp:ListItem> 
     <asp:ListItem> 4 </asp:ListItem> 
     <asp:ListItem> 5 </asp:ListItem> 
     <asp:ListItem> 6 </asp:ListItem> 
     <asp:ListItem> 7 </asp:ListItem> 
     <asp:ListItem> 8 </asp:ListItem> 
     <asp:ListItem> 9 </asp:ListItem> 
     ...ect 
</asp:CheckBoxList> 

我想,一定有某種ASP標記或東西,讓我清除複選框這個名單的。

+0

-1在這個問題上?請解釋。這似乎是經過深思熟慮,鋪陳和描述。 – 2011-12-31 04:12:48

回答

6

你在找什麼是RepeatColumns財產和RepeatDirection財產。事情是這樣的:

<asp:CheckBoxList ID="Numbers" runat="server" AutoPostBack = "true" 
    RepeatColumns="2" RepeatDirection="Vertical"> 
     <asp:ListItem> 1 </asp:ListItem> 
     <asp:ListItem> 2 </asp:ListItem> 
     <asp:ListItem> 3 </asp:ListItem> 
     <asp:ListItem> 4 </asp:ListItem> 
     <asp:ListItem> 5 </asp:ListItem> 
     <asp:ListItem> 6 </asp:ListItem> 
     <asp:ListItem> 7 </asp:ListItem> 
     <asp:ListItem> 8 </asp:ListItem> 
     <asp:ListItem> 9 </asp:ListItem> 
     ...ect 
</asp:CheckBoxList> 

按照下面的參考,也可以以編程方式在您的代碼隱藏利用設置該屬性的​​:

Numbers.RepeatDirection = RepeatDirection.Vertical; 
Numbers.RepeatColumns = 2; 

請參閱此作爲參考:How to: Set Layout in a CheckBoxList Web Server Control

+0

非常好,那正是我需要的。謝謝! – 2011-12-31 03:38:09

+0

@美國。沒問題,我很樂意提供幫助。 – 2011-12-31 03:44:36

4

是的,使用RepeatColumns屬性。如果您只希望它在動態綁定控件並顯示多於10個項目後以這種方式顯示,則只需對Page_Load中的項目進行計數並將RepeatColumns設置爲2(如果數據源包含的元素超過10個)。

Here是msdn文檔的更多信息。