一、展示页面添加控件 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; }
三、验证
完成后的样子
保存的值展示
数据库