?
本文檔使用 PHP中文網(wǎng)手冊(cè) 發(fā)布
CheckBoxList 控件用于創(chuàng)建多選的復(fù)選框組。
每個(gè) CheckBoxList 控件中的可選項(xiàng)都是由 ListItem 元素定義的!
提示:該控件支持?jǐn)?shù)據(jù)綁定!
屬性 | 描述 | .NET |
---|---|---|
CellPadding | 表格單元格的邊框與內(nèi)容之間的像素?cái)?shù)。 | 1.0 |
CellSpacing | 表格單元格之間的像素?cái)?shù)。 | 1.0 |
RepeatColumns | 當(dāng)顯示復(fù)選框組時(shí)所用的列數(shù)。 | 1.0 |
RepeatDirection | 規(guī)定復(fù)選框組水平重復(fù)還是垂直重復(fù)。 | 1.0 |
RepeatLayout | 復(fù)選框組的布局。 | 1.0 |
runat | 規(guī)定該控件是服務(wù)器控件。必須設(shè)置為 "server"。 | 1.0 |
TextAlign | 文本出現(xiàn)在復(fù)選框的哪一側(cè)。 | 1.0 |
AppendDataBoundItems,?AutoPostBack,?CausesValidation,?DataTextField,?DataTextFormatString,?DataValueField,?Items,?runat,?SelectedIndex,?SelectedItem,?SelectedValue,?TagKey,?Text,?ValidationGroup,?OnSelectedIndexChanged
ListControl 控件包括列表控件的所有基本功能。繼承自此控件的控件包括:CheckBoxList, DropDownList, ListBox 以及 RadioButtonList 控件。
如需完整描述,請(qǐng)?jiān)L問(wèn) ListControl 標(biāo)準(zhǔn)屬性。
AccessKey,?Attributes,?BackColor,?BorderColor,?BorderStyle,?BorderWidth,?CssClass,?Enabled,?Font,?EnableTheming,?ForeColor,?Height,?IsEnabled,?SkinID,?Style,?TabIndex,?ToolTip,?Width
如需完整描述,請(qǐng)?jiān)L問(wèn) Web 控件標(biāo)準(zhǔn)屬性。
AppRelativeTemplateSourceDirectory,?BindingContainer,?ClientID,?Controls,?EnableTheming,?EnableViewState,?ID,?NamingContainer,?Page,?Parent,?Site,?TemplateControl,?TemplateSourceDirectory,?UniqueID,?Visible
如需完整描述,請(qǐng)?jiān)L問(wèn) 控件標(biāo)準(zhǔn)屬性。
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>
在本例中,我們?cè)?.aspx 文件中聲明了一個(gè) CheckBoxList 控件。然后我們?yōu)?SelectedIndexChanged 事件創(chuàng)建了一個(gè)事件句柄。這個(gè)可選列表包含六個(gè)復(fù)選框。當(dāng)用戶選中其中之一,頁(yè)面會(huì)自動(dòng)傳回服務(wù)器,并執(zhí)行 Check 子例程。該子例程會(huì)遍歷控件的 Items 集合,并測(cè)試每個(gè)項(xiàng)目的 Selected 屬性。被選的項(xiàng)目會(huì)顯示在 Label 控件中。