选择控件

一、ListBox控件

1.定义:用于显示一组列表项。

2.常用属性:

ListBox控件的常用属性
属性 说明
Items 获取列表控件项的集合
SelectionMode 获取或设置ListBox控件的选择格式
SelectedIndex 获取或设置列表控件中选定项的最低序号索引
SelectedItem 获取列表控件中索引最小的选中项
SelectedValue 获取列表控件中选定项的值,或选择列表控件中包含指定值的项
Rows 获取或设置ListBox控件中显示的行数  
DataSource 获取或设置对象,数据绑定控件从该对象中检索其数据项列表
ID 控件的唯一标识,不能重复

       (1)Items:,用来获取列表中的项,加载方式:1)属性面板添加;2)Items.Add添加

       (2)SelectedMode:用来获取列表控件的选择模式,两种方式:1)单选;2)多选

后台代码:

        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>

页面形式:

 

页面代码:

<select size="4" name="ListBox1" id="ListBox1">

 二、DropDownList控件

1.定义:选择控件,只允许用户选择一项。

2.常用属性:

DropDownList的常用属性
属性 说明
Items 获取列表控件项的集合
SelectedIndex 获取或设置列表中选定项的最低序号索引
SelectedItem 获取列表中选中的选项的索引
SelectedValue 获取列表控件中选定项的值,或选择列表控件中包含指定值的选项
AutoPostBack 获取或设置一个值,该值指示当用户更改列表中的选定内容时,是否自动产生向服务器回发
DataSource 获取或设置对象,数据绑定控件从该对象中检索其数据项列表
ID 获取或设置分配给服务器控件的编程标识符

3.常用方法:1)用DataSource绑定数据源;2)用DataBind绑定数据

4.常用事件:SelectedIndexChanged,当控件中选定选项发生改变时,触发SelectedIndexChanged事件。

后台代码:

 <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

页面形式:

页面代码:

<select name="DropDownList1" id="DropDownList1">

三、RadioButton控件与RadioButtonList控件

1.定义:RadioButton是单选按钮控件,RadioButtonList是单选按钮组。

2.常用属性:

RadioButton和RadioButtonList控件的常用属性
属性 说明
AutoPostBack 获取或设置一个值,该值指示在单击控件时,是否自动回发到服务器
CausesValidation 获取或设置一个值,该值指示在单击控件时,是否执行验证
Checked(RadioButtonList不存在此属性) 标记RadioButton是否被选中
GroupName 获取或设置单选按钮所属的组名
Text(RadioButtonList不存在此属性) 获取或设置控件显示的文本
TextAlign 文本的对齐方式
Enabled 控件是否可用
ID 控件唯一标识,不能重复

         (1)GroupName:只有当不同的RadioButton控件的GroupName相同时,才能互斥。

后台代码:

        <asp:RadioButton ID="RadioButton1" runat="server" text="1314"/>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
            <asp:ListItem>1254</asp:ListItem>
        </asp:RadioButtonList>

页面形式:

页面代码:

        <input id="RadioButton1" type="radio" name="RadioButton1" value="RadioButton1" /><label for="RadioButton1">1314</label>
        <table id="RadioButtonList1">
    <tr>
        <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1254" /><label for="RadioButtonList1_0">1254</label></td>
    </tr>

五、CheckBox控件与CheckBoxList控件

1.定义:CheckBox控件是复选框,CheckBoxList控件是一组复选框

2.常用属性:

CheckBox和CheckBoxList控件的常用属性
属性 说明
AutoPostBack 获取或设置一个值,该值指示在单击控件时,是否自动回发到服务器
CausesValidation 获取或设置一个值。该值指示在单击控件时,是否执行验证
Checked(CheckBoxList不存在此属性) 表示是否选中
Text(CheckBoxList不存在此属性) 控件的文本
TextAlign 文本对齐方式
Enabled 控件是否可用
ID 控件唯一标识,不能重复

3.常用事件:

    CheckChanged事件:

后台代码:

        <asp:CheckBox ID="CheckBox1" runat="server" text="123"/>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem>1321</asp:ListItem>
        </asp:CheckBoxList>

页面形式:

页面代码:

        <input id="CheckBox1" type="checkbox" name="CheckBox1" /><label for="CheckBox1">123</label>
        <table id="CheckBoxList1">
    <tr>
        <td><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" value="1321" /><label for="CheckBoxList1_0">1321</label></td>
    </tr>
原文地址:https://www.cnblogs.com/bosamvs/p/5687191.html