码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2014-07-02 22:57:10      阅读:388      评论:0      收藏:0      [点我收藏+]

标签:数据   os   for   io   数据库   new   

前台:

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

 

RadioButtonList 和CheckBoxList根据后天数据库的值加载时选中其选项,布布扣,bubuko.com

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

标签:数据   os   for   io   数据库   new   

原文地址:http://www.cnblogs.com/fang645421992/p/3818887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!