Checkboxlist Asp.Net C#
本文关键字:Net Asp Checkboxlist | 更新日期: 2023-09-27 18:19:04
是否有办法在asp.net中包装一个复选框比如说你的列表中有20个复选框,有两列,每列10个。例子:
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标记之类的东西可以让我清理这个复选框列表
您正在寻找的是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>
根据下面的参考,您也可以在代码中使用RepeatDirection
enum以编程方式设置此属性:
Numbers.RepeatDirection = RepeatDirection.Vertical;
Numbers.RepeatColumns = 2;
如何:在CheckBoxList Web Server控件中设置布局
是,使用RepeatColumns属性。如果你只希望它在你动态绑定控件并且它有超过10个元素之后显示,只需要计算Page_Load中的项数,并且如果数据源包含超过10个元素,则将RepeatColumns设置为2。