RadioButtonList的使用

RadioButtonList的使用

概述:

RadioButtonList 控件为网页开发者提供了一组单选button,这些button能够通过数据绑定动态生成。该控件包括一个items集合,集合中的成员与列表中的各项相相应。

                <div class="rblStyle">
                <asp:RadioButtonList ID="rblChangQHT" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Text="是" Value="1"></asp:ListItem> 
                <asp:ListItem Text="否" Value="0"></asp:ListItem>
                </asp:RadioButtonList></div>


1.RadioButtonList的校验

            var rb_ChangQHT = document.getElementById("rblChangQHT");
            var ShiF = rb_ChangQHT.getElementsByTagName("INPUT");
            var result = false;
            for (var i = 0; i < ShiF.length; i++) {
                if (ShiF[i].checked) {
                    result = true;
                    break;
                }
            }
            if (!result) {
                alert("是否为中长期合同为必填项!");
                return false;
            }


 

2.RadioButtonList的样式调整

(1)去掉难看的单选边框

RadioButtonList的使用

为RadioButtonList控件加入<div>层,并为div设置样式

.rblStyle{100%;height:auto;}
.rblStyle input{border-style:none;}


RadioButtonList的使用

3.onselectedindexchanged事件

像下拉控件dropdownlist控件一样,它也有onselectedindexchanged事件,当选项改变后进行触发

注意点是:控件中的AutoPostBack属性一定设为"True",这样server端才知道你的选项改变了,并触发对应事件