Latest web development tutorials

ASP.NET CheckBoxList 控件

Web Server Controls Web服務器控件

定義和用法

CheckBoxList 控件用於創建多選的複選框組。

每個CheckBoxList 控件中的可選項都是由ListItem 元素定義的!

提示:該控件支持數據綁定!


屬性

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

ListControl 標準屬性

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

ListControl 控件包括列表控件的所有基本功能。 繼承自此控件的控件包括:CheckBoxList, DropDownList, ListBox 以及RadioButtonList 控件。

如需完整描述,請訪問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
在本例中,我們在.aspx 文件中聲明了一個CheckBoxList 控件。 然後我們為SelectedIndexChanged 事件創建了一個事件句柄。 這個可選列表包含六個複選框。 當用戶選中其中之一,頁面會自動傳回服務器,並執行Check 子例程。 該子例程會遍歷控件的Items 集合,並測試每個項目的Selected 屬性。 被選的項目會顯示在Label 控件中。


Web Server Controls Web服務器控件