views:

209

answers:

2

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

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

How do I do it?

A: 

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.

jlech
+5  A: 

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
Phaedrus
Just a quick thanks and +1 for this...
drachenstern