?
? ????? PHP ??? ???? ??? ?? ??
CheckBoxList 控件用于創(chuàng)建多選的復選框組。
每個 CheckBoxList 控件中的可選項都是由 ListItem 元素定義的!
提示:該控件支持數(shù)據(jù)綁定!
屬性 | 描述 | .NET |
---|---|---|
CellPadding | 表格單元格的邊框與內(nèi)容之間的像素數(shù)。 | 1.0 |
CellSpacing | 表格單元格之間的像素數(shù)。 | 1.0 |
RepeatColumns | 當顯示復選框組時所用的列數(shù)。 | 1.0 |
RepeatDirection | 規(guī)定復選框組水平重復還是垂直重復。 | 1.0 |
RepeatLayout | 復選框組的布局。 | 1.0 |
runat | 規(guī)定該控件是服務(wù)器控件。必須設(shè)置為 "server"。 | 1.0 |
TextAlign | 文本出現(xiàn)在復選框的哪一側(cè)。 | 1.0 |
AppendDataBoundItems,?AutoPostBack,?CausesValidation,?DataTextField,?DataTextFormatString,?DataValueField,?Items,?runat,?SelectedIndex,?SelectedItem,?SelectedValue,?TagKey,?Text,?ValidationGroup,?OnSelectedIndexChanged
ListControl 控件包括列表控件的所有基本功能。繼承自此控件的控件包括:CheckBoxList, DropDownList, ListBox 以及 RadioButtonList 控件。
如需完整描述,請訪問 ListControl 標準屬性。
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> <html> <body> <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> </body> </html>
在本例中,我們在 .aspx 文件中聲明了一個 CheckBoxList 控件。然后我們?yōu)?SelectedIndexChanged 事件創(chuàng)建了一個事件句柄。這個可選列表包含六個復選框。當用戶選中其中之一,頁面會自動傳回服務(wù)器,并執(zhí)行 Check 子例程。該子例程會遍歷控件的 Items 集合,并測試每個項目的 Selected 屬性。被選的項目會顯示在 Label 控件中。