Web服务器控件:CheckBoxList控件
http://www.itjxue.com 2015-07-17 01:59 来源:未知 点击次数:
阅读此文请先查看:ASP.NET入门教程:Web服务器控件,简单讲述了Web服务器控件的使用方法。
定义和用法
CheckBoxList控件用来建立一个多选的复选框组。
CheckBoxList控件中的每个可选项由一个ListItem元素来定义!
提示:此控件支持数据绑定!
属性
属性 | 说明 |
---|---|
AutoPostBack | 指定在某一项的选择状态发生改变后表单是否被立即投递的一个布尔值。默认值是false |
CellPadding | 单元格边界与复选框组之间的间距,以象素表示 |
DataSource | 使用的数据源 |
DataTextField | 数据源中的一个字段,将被显示于复选框组中 |
DataValueField | 数据源中的一个字段,指定复选框组中每个可选项的值 |
id | 此控件的唯一id |
OnSelectedIndexChanged | 当某项的选择状态发生改变时将执行的函数的名称 |
RepeatColumns | 显示复选框组时使用的列数。默认值是"1" |
RepeatDirection | 指定复选框组将按水平还是垂直方向重复。合法的值为"Horizontal" 和 "Vertical"。默认值是Vertical |
RepeatLayout | 复选框组的布局。可以是 "Table" 或 "Flow"。默认值是Table |
runat | 规定此控件是服务器控件。必须被设置为"server" |
TextAlign | 文本出现在复选框的哪一侧(右侧或左侧) |
示例
在此示例中我们在一个.aspx文件中声明一个CheckBoxList控件。然后我们为SelectedIndexChanged事件建立一个事件句柄。此可选列表包含了6个复选框。当用户勾选其中之一的时候,页面立即被投递回服务器,并且Check子程序被执行。该子程序在控件的选项集合中循环测试每项的Selected属性。被选中项被显示于Label控件中。本信息代表文章来源网页教学itjxue.com请大家去www.itjxuecom浏览!
<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> <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> |
(责任编辑:IT教学网)
上一篇:Web服务器控件:Style控件
下一篇:Web服务器控件:Panel控件