RadioButtonList 和CheckBoxList根据后天数据库的值加载时选中其选项

前台:

<x:RadioButtonList ID="rbSex" Label="性别" runat="server"  >
                                       <x:RadioItem Text="男" Value="男" Selected="true"  />
                                        <x:RadioItem Text="女" Value="女" />
                                    </x:RadioButtonList>

 

前台:  <x:CheckBoxList ID="cbl" runat="server" ColumnNumber="2" Label="角色" ></x:CheckBoxList>

绑定数据:  protected void inti()
        {
            List<RoleInfo> roleList = roleDAL.List();
            if (roleList == null)
            {
                Alert.Show("加载角色信息失败!", MessageBoxIcon.Warning);
            }
           
            cbl.DataTextField = "Name";
            cbl.DataValueField = "ID";
         
            cbl.DataSource = roleList;
            cbl.DataBind();
        }

RadioButtonList根据数据库的值加载显示选中:

   if (userInfo.Sex.Equals("男"))
                    {
                        rbSex.SelectedIndex=0;
                    }
                    else
                    {
                        rbSex.SelectedIndex = 1;
                       
                    }

CheckBoxList根据数据库的值加载显示选中:

 List<RoleInfo> list = roleDAL.ListRoleByUserID(new Guid(Request.QueryString["id"]));
                        if (list != null)
                        {
                            
                            string[] arry = cbl.SelectedValueArray;//cbl的值选项
                            for (int i = 0; i<roleDAL.List().Count; i++)//i<角色信息表的总数量条数。
                            {
                                if (cbl.Items[i].Value == list.FirstOrDefault().ID.ToString())
                                {
                                    cbl.Items[i].Selected = true;
                                }
                            }
                        }

 

转载于:https://www.cnblogs.com/fang645421992/p/3818887.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值