• 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;
                                    }
                                }
                            }

  • 相关阅读:
    traversal outlook folders
    vba get contact name in outlook
    merge all worksheets in current directory
    pandas Dataframe more filter
    Dataframe swap columns
    【数据分析&数据挖掘】数组的数据类型
    【数据分析&数据挖掘】数组的创建
    【数据分析&数据挖掘】矩阵的运算
    【数据分析&数据挖掘】矩阵的创建
    【python基础】装饰器
  • 原文地址:https://www.cnblogs.com/fang645421992/p/3818887.html
Copyright © 2020-2023  润新知