zoukankan      html  css  js  c++  java
  • .NET ------ CheckBoxList 的用法

    一、展示页面添加控件 CheckBoxList 控件

    RepeatColumns :指定一行放几个
    CssClass :添加样式 ,如不展示表格边框 ttable_border_none
           <asp:CheckBoxList ID="tbCheckBoxList_LessonTeacher" runat="server" RepeatColumns="4" CssClass="ttable_border_none">
        </asp:CheckBoxList>
     

    二、 逻辑页面

    1、给 ChenkBoxList 赋值

    需要 关键字和 对应的值

     {//课程教师
                ITEM.Inherits.Bll.bllFourAdminUser _bllUser = new bllFourAdminUser();
                List<ITEM.Model.FourAdminUser> mList = _bllUser.GetListSelFourAdminUser3("AdminGuid,LoginID,UserName", base.EnterpriseGuid, " and RoleGuid in(select RoleGuid from tbFourAdminRole where RoleTypeFlag<8000)");
                this.tbCheckBoxList_LessonTeacher.DataTextField = "UserName";
                this.tbCheckBoxList_LessonTeacher.DataValueField = "AdminGuid";
                this.tbCheckBoxList_LessonTeacher.DataSource = mList;
                this.tbCheckBoxList_LessonTeacher.DataBind();
                
                //this.CheckBoxList1.Items.Add(mList[0].UserName);
                
                // for (int i=0; i<mList.Count; i++)
                // {
                //   this.CheckBoxList1.Items.Add(mList[i].UserName);
                // }
            }

    2、判断是否选中

    //循环
                for (int i=0;i<=this.tbCheckBoxList_LessonTeacher.Items.Count-1;i++)
                {
                    //判断是否选中
                    if (_classlessonsort.LessonTeacher_loginGuid.IndexOf(this.tbCheckBoxList_LessonTeacher.Items[i].Value)>=0)
                    {
                        this.tbCheckBoxList_LessonTeacher.Items[i].Selected = true;
                    }
                }

    3、保存

            {
                //初始化
                string sGuid = string.Empty;
                string sName = string.Empty;
                for (int i=0;i<=this.tbCheckBoxList_LessonTeacher.Items.Count-1;i++)
                {
                    //判断有无选中
                    if (this.tbCheckBoxList_LessonTeacher.Items[i].Selected)
                    {
                        //赋值,中间用 " , " 号间隔
                        string sign = sGuid == string.Empty ? "" : ",";
                        sGuid += sign + this.tbCheckBoxList_LessonTeacher.Items[i].Value;
                        sName += sign + this.tbCheckBoxList_LessonTeacher.Items[i].Text;
                    }             
                }
                _classlessonsort.LessonTeacher_loginGuid = sGuid;
                _classlessonsort.LessonTeacher_loginName = sName;
    
            }

    三、验证

    完成后的样子

     保存的值展示

     数据库

  • 相关阅读:
    别让代码执行不必要的路径和让数据绑定执行了多次
    使用Excel学习英语单词
    如何通过访问记录改善网站质量
    Vs.net2005强势功能:数据源
    新产品:英语单词查找返回表格式结果
    为什么Cpu不能以100%运行 [不完全版]
    乐透彩票研究分析系统
    集成电路发明者杰克·基尔比 IC Inventor Jack Kilby
    ZigBee技术及其应用
    Unix传奇(上篇)
  • 原文地址:https://www.cnblogs.com/obge/p/13965677.html
Copyright © 2011-2022 走看看