zoukankan      html  css  js  c++  java
  • 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;
                                    }
                                }
                            }

  • 相关阅读:
    maven的pom.xml文件详细说明
    python 给视频添加马赛克
    cv2.VideoCapture 图像旋转问题
    三分钟理解知识蒸馏
    深度学习、机器学习常见概念及理解(持续更新)
    python用直方图规定化实现图像风格转换
    1分钟理解人体姿态估计与行为识别
    数据清洗要点
    3分钟理解NMS非极大值抑制
    python用pandas遍历csv文件
  • 原文地址:https://www.cnblogs.com/fang645421992/p/3818887.html
Copyright © 2011-2022 走看看