51Aspx 源码服务专家 社区资讯
开发文档

ASP.NET CheckBoxList 控件

属性描述.NET
CellPadding表格单元格的边框与内容之间的像素数1.0
CellSpacing表格单元格之间的像素数1.0
RepeatColumns当显示复选框组时所用的列数1.0
RepeatDirection规定复选框组水平重复还是垂直重复1.0
RepeatLayout复选框组的布局1.0
runat规定该控件是服务器控件。必须设置为 "server"1.0
TextAlign文本出现在复选框的哪一侧1.0

ASP.NET CheckBoxList CellPadding 属性

ASP.NET CheckBoxList CellPadding 属性用于获取或设置表格单元格的边框与内容之间的像素数

该函数仅在 RepeatLayout 属性设置为 "Table" 时有效

语法

<asp:CheckBoxList CellPadding="pixels" runat="server">Some Content</asp:CheckBoxList>
属性描述
pixels规定表格单元格的边框与内容之间的像素数

范例

下面的范例设置了 CheckBoxList 控件的 CellPadding 属性

<form runat="server">
<asp:CheckBoxList id="rb1" runat="server" CellPadding="15">Some content</asp:CheckBoxList>
</form>

ASP.NET CheckBoxList CellSpacing 属性

ASP.NET CheckBoxList CellSpacing 属性用于获取或设置 CheckBoxList 中表格单元格之间的像素数

该函数仅在 RepeatLayout 设置为 "Table" 时有效(默认)

语法

<asp:CheckBoxList CellSpacing="pixels" runat="server">Some Content</asp:CheckBoxList>
属性描述
pixels规定表格单元格之间的像素数

范例

下面的范例设置了 CheckBoxList 控件的 CellSpacing 属性

<form runat="server">
<asp:CheckBoxList id="rb1" runat="server" CellSpacing="15">Some content</asp:CheckBoxList>
</form>

ASP.NET CheckBoxList RepeatColumns 属性

ASP.NET CheckBoxList RepeatColumns 属性用于获取或设置当显示复选框列时所使用的列数

语法

<asp:CheckBoxList RepeatColumns="num" runat="server">Some Content</asp:CheckBoxList>
属性描述
num规定要显示的列数。默认是 "0"(未设置)

范例

下面的范例把 CheckBoxList 控件中的 RepeatColumns 属性设置为 "2"

<form runat="server">
<asp:CheckBoxList id="rb1" runat="server" RepeatColumns="2">Some content
</asp:CheckBoxList>
</form>

ASP.NET CheckBoxList RepeatDirection 属性

ASP.NET CheckBoxList RepeatDirection 属性用于获取或设置 CheckBoxList 中的项目垂直显示还是水平显示

语法

<asp:CheckBoxList RepeatDirection="mode" runat="server">Some Content</asp:CheckBoxList>
属性描述
mode规定 CheckBoxList 中项目的布局方向

可能的值:
Horizontal - 项目水平显示
Vertical - 默认。项目垂直显示

范例

下面的范例设置了 CheckBoxList 控件的 RepeatDirection

<form runat="server">
<asp:CheckBoxList id="cb1" runat="server" RepeatDirection="Horizontal">Some content</asp:CheckBoxList>
</form>

ASP.NET CheckBoxList RepeatLayout 属性

ASP.NET CheckBoxList RepeatLayout 属性用于获取或设置如何显示在 CheckBoxList 中的项目

语法

<asp:CheckBoxList RepeatLayout="mode" runat="server">Some Content</asp:CheckBoxList>
属性描述
mode规定 CheckBoxList 中项目的布局

可能的值:
Flow - 项目不显示在表格中
Table - 默认。项目显示在表格中

范例

下面的范例设置了 CheckBoxList 控件的 RepeatLayout

<form runat="server">
<asp:CheckBoxList id="cb1" runat="server" RepeatLayout="Flow">Some content
</asp:CheckBoxList>
</form>

ListControl 标准属性

  • AppendDataBoundItems
  • AutoPostBack
  • CausesValidation
  • DataTextField
  • DataTextFormatString
  • DataValueField
  • Items
  • runat
  • SelectedIndex
  • SelectedItem
  • SelectedValue
  • TagKey
  • Text
  • ValidationGroup
  • OnSelectedIndexChanged

如果想要查看完整描述,可以访问我们的 ListControl 标准属性

Web 控件标准属性

  • AccessKey
  • Attributes
  • BackColor
  • BorderColor
  • BorderStyle
  • BorderWidth
  • CssClass
  • Enabled
  • Font
  • EnableTheming
  • ForeColor
  • Height
  • IsEnabled
  • SkinID
  • Style
  • TabIndex
  • ToolTip
  • Width

如果想要查看完整描述,可以访问我们的 Web 控件标准属性

控件标准属性

  • AppRelativeTemplateSourceDirectory
  • BindingContainer
  • ClientID
  • Controls
  • EnableTheming
  • EnableViewState
  • ID
  • NamingContainer
  • Page
  • Parent
  • Site
  • TemplateControl
  • TemplateSourceDirectory
  • UniqueID
  • Visible

如果想要查看完整描述,可以访问我们的 控件标准属性

范例

CheckBoxList

<script  runat="server">
Sub Check(sender As Object, e As EventArgs)
   dim i
   mess.Text="<p>Selected Item(s):</p>"
   for i=0 to check1.Items.Count-1
     if check1.Items(i).Selected then
       mess.Text+=check1.Items(i).Text + "<br>"
     end if
   next
End Sub
</script>

<!DOCTYPE html>
<meta charset="utf-8" />

<form runat="server">
<asp:CheckBoxList id="check1" AutoPostBack="True"
TextAlign="Right" OnSelectedIndexChanged="Check"
runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:CheckBoxList>
<br>
<asp:label id="mess" runat="server"/>
</form>

范例中,我们声明了一个 CheckBoxList 控件然后我们为 SelectedIndexChanged 事件创建了一个事件句柄这个可选列表包含六个复选框当用户选中其中之一,页面会自动传回服务器,并执行 Check 子例程该子例程会遍历控件的 Items 集合,并测试每个项目的 Selected 属性被选的项目会显示在 Label 控件中