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

    三、验证

    完成后的样子

     保存的值展示

     数据库

  • 相关阅读:
    java实现获取当前年月日 小时 分钟 秒 毫秒
    四种常见的 POST 提交数据方式(application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml)
    Cannot send, channel has already failed:
    Java 枚举(enum) 详解7种常见的用法
    C语言指针详解(经典,非常详细)
    ActiveMQ进阶配置
    Frame size of 257 MB larger than max allowed 100 MB
    SpringJMS解析--监听器
    SpringJMS解析-JmsTemplate
    delphi 修改代码补全的快捷键(由Ctrl+Space 改为 Ctrl + alt + Space)
  • 原文地址:https://www.cnblogs.com/obge/p/13965677.html
Copyright © 2020-2023  润新知