开发者

ASP.NET having a checkboxlist with my nice checkboxes in a 4x5 grid

I have a checkboxlist which either displays them in a list

A
B
C
D

or horizontally

A B C D

I want to arrange them in a nice grid lik开发者_开发问答e this

A B C D
E F G H
I J K L

How do I do it?


You need to set the RepeatDirection and RepeatColumns properties of the CheckBoxList.

<asp:CheckBoxList ID="myCheckBoxList" runat="server" 
     RepeatColumns="4" RepeatDirection="Horizontal">
 <asp:ListItem>A</asp:ListItem>
 <asp:ListItem>B</asp:ListItem> 
 <asp:ListItem>C</asp:ListItem>
 <asp:ListItem>D</asp:ListItem>
 <asp:ListItem>E</asp:ListItem>
 <asp:ListItem>F</asp:ListItem>
 <asp:ListItem>G</asp:ListItem>
 <asp:ListItem>H</asp:ListItem>
 <asp:ListItem>I</asp:ListItem>
 <asp:ListItem>J</asp:ListItem>
 <asp:ListItem>K</asp:ListItem>
 <asp:ListItem>L</asp:ListItem>
 <asp:ListItem>M</asp:ListItem>
 <asp:ListItem>N</asp:ListItem>
 <asp:ListItem>O</asp:ListItem>
 <asp:ListItem>P</asp:ListItem>
 <asp:ListItem>Q</asp:ListItem>
 <asp:ListItem>R</asp:ListItem>
 <asp:ListItem>S</asp:ListItem>
 <asp:ListItem>T</asp:ListItem>
</asp:CheckBoxList>

This will render a 4x5 grid of check boxes.

A B C D
E F G H
I J K L
M N O P
Q R S T


Well if your items are always going to be on a static 4x5 grid, you're probably best off just hardcoding one yourself.

Otherwise you're going to have to use a control like Data List to bind your datasource to the DL of just Check box controls. The nice thing about Data List is that it will at least let you control the number of repeating columns and which direction it repeats in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜