.Net ------ 多选

1、使用控件  asp:CheckBoxList 

<tr>
<td align="right" bgcolor="#F5F5F5">学校性质:</td>
<td align="left" bgcolor="#FFFFFF" colspan="5"><asp:CheckBoxList ID="checkJobUser_SchoolNature_4144" runat="server" RepeatColumns="12" CssClass="ttable_border_none"></asp:CheckBoxList></td>
</tr>

显示如下:

RepeatColumns="12"   //表示一行展示 12 个 ,将原本的多行变成一行
CssClass="ttable_border_none"  //表示调用css 样式不显示表格边框

 

2、赋值

            #region 学校性质 4144
            {
                List<ITEM.Model.qdCnt4.FourCollsType> mList8 = _bllTypeColls.Get_Ex_FourCollsTypeListByIDLevel("TypeCollGuid,TypeCollName",base.EnterpriseGuid,4144,1,0f);
                this.checkJobUser_SchoolNature_4144.DataTextField = "TypeCollName";
                this.checkJobUser_SchoolNature_4144.DataValueField = "TypeCollGuid";
                this.checkJobUser_SchoolNature_4144.DataSource = mList8;
                this.checkJobUser_SchoolNature_4144.DataBind();
            }
            #endregion

 

3、保存

     if(this.checkJobUser_SchoolNature_4144.SelectedValue != string.Empty)
     {//学校性质
            string strGuid = "";
            string strText = "";
            foreach(ListItem item in this.checkJobUser_SchoolNature_4144.Items)
            {
                if(item.Selected == true)
                {
                    string sign = strGuid == string.Empty ? "" : ",";
                    strGuid += sign + item.Value;
                    strText += sign + item.Text;
                }
            }
            _job_userinfo.JobUser_SchoolNature_4144_Guid = strGuid;//学校性质,多选,以逗号分隔
            _job_userinfo.JobUser_SchoolNature_4144_Name = strText;//学校性质,多选,以逗号分隔
        }

 

4、将保存的显示

                //学校性质,多选,以逗号分隔
                strs = job_userinfo.JobUser_SchoolNature_4144_Guid.Split(',');
                foreach(var item in strs)
                {
                    foreach(ListItem it in this.checkJobUser_SchoolNature_4144.Items)
                    {
                        if(it.Value == item && item != "")
                        {
                            it.Selected = true;
                        }
                    }

                }

 如下:

 

posted on 2021-05-31 22:09  obge  阅读(68)  评论(0编辑  收藏  举报