专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

C# CheckBoxList绑定值,设置及获取

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:43:24       共计:3627 浏览
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" OnItemDataBound="Repeater1_ItemDataBound">
                            <ItemTemplate>
                                <p >
                                <asp:HiddenField ID="hfGetId" Value='<%#Eval("TMIdInt") %>' runat="server" />
                                <span style="color:red;"><%#Eval("NameStr") %></span>
                                <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal"></asp:CheckBoxList>
                                </p>
                            </ItemTemplate>

                        </asp:Repeater>


Maticsoft.Model.DR_TRoles _TRoles = _bll_TRoles.GetModel(int.Parse(user.TRIdInt.ToString()));
        if (_TRoles != null && _TRoles.Cids != null)
        {
            DataSet ds = _bll_TMenus.GetList(" TMIdInt in(" + _TRoles.Cids + ") order by SortTint ASC");
            Repeater1.DataSource = ds;
            Repeater1.DataBind();

            string[] arr = user.Cids.Split(',');
            for (int i = 0; i < arr.Length; i++)
            {
                foreach (Control c in this.Repeater1.Controls)
                {
                    CheckBoxList cbx = (CheckBoxList)c.FindControl("CheckBoxList1");
                    if (cbx != null)
                    {
                        foreach (ListItem item in cbx.Items)
                        {
                            if (item.Value==arr[i])
                            {
                                item.Selected = true;
                            }
                        }
                    }
                }
            }
        }



string cids = string.Empty;
            foreach (Control c in this.Repeater1.Controls)
            {
                CheckBoxList cbx = (CheckBoxList)c.FindControl("CheckBoxList1");
                if (cbx != null)
                {
                    foreach (ListItem item in cbx.Items)
                    {
                        if (item.Selected == true)
                        {
                            cids += item.Value+",";
                        }
                    }
                }
            }
            user.Cids = cids.TrimEnd(',');

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:分布式系统设计系列 -- 基本原理及高可用策略 | ·下一条:C#多线程之三:解决多线程编程中大并发数等待唤醒的问题

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有