radiobuttonList的做法

js验证:

  var sex = document.getElementsByName("rbl_sex");

   var flag = true;
            for (var i = 1; i < sex.length; i++) {
                if (sex[i].checked == true) {
                    flag = false;
                }
            }
            if (flag) {
                alert("请选择性别!");
                return false;
            }

 

页面操作:

  <asp:RadioButtonList ID="rbl_sex" runat="server" RepeatDirection="Horizontal">
                                                                    <asp:ListItem Text="男" Value="0" />
                                                                    <asp:ListItem Text="女" Value="1" />
                                                                </asp:RadioButtonList>

 

后台赋值:

     if (LeagueCarOwer.性别 == "男")
            {
                rbl_sex.SelectedValue = "0";
            }
            else
            {
                rbl_sex.SelectedValue = "1";
            }

 

插入数据库:

   LeagueCarOwer.Dat_性别 = Convert.ToDecimal(rbl_sex.SelectedValue);

 

checkbox选中:
car.加盟邀请=0;
if (ckb_carYQEnable.Checked)
        {
            car.加盟邀请 = 0;
        }
        else
        {
            car.加盟邀请 = 1;
        }

你可能感兴趣的:(radiobuttonList的做法)