CheckBoxList定义每行个数后,自动换行

本文介绍了一个关于CheckBoxList控件的布局设置及数据填充的方法。通过设定每行的项目数量来实现自动换行,并在选择不同的属性时,动态更新CheckBoxList的内容。此方法适用于需要固定每行显示数量的场景。
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CheckBoxList1.SelectedValue.Count() >0)
            {
                //类别id
                int categoryId = BLLUtils.Toint(DropDownList2.SelectedValue, 0);

                //选中的属性的id
                ArrayList propertyIds = new ArrayList();
                for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
                {
                    if (this.CheckBoxList1.Items[i].Selected == true)
                    {
                        propertyIds.Add(this.CheckBoxList1.Items[i].Value);
                    }
                }

                CheckBoxList2.Items.Clear();
                for (int i = 0; i < propertyIds.Count; i++)
                {
                    ProductPropertyValueDataSet ds = ProductPropertyValue.SelectValuePropertyDataById(categoryId, BLLUtils.Toint(propertyIds[i], 0));
                    if (ds != null && ds.Count > 0)    //有数据增加listitem
                    {
                        foreach (var item in ds.DataList)
                        {
                            CheckBoxList2.Items.Add(new ListItem(item.ValueProperty, item.ValueId.ToString() + "-" + propertyIds[i].ToString()));
                        }

                        if (CheckBoxList2.Items.Count < 12*(i+1))   //CheckBoxList的项数为12的倍数,每行不足12个补足12个无数据的不显示
                        {
                            for (int m = CheckBoxList2.Items.Count; m < 12 * (i + 1); m++)
                            {
                                CheckBoxList2.Items.Add(new ListItem(" "," "));
                                CheckBoxList2.Items[m].Attributes.Add("style", "display:none");
                            }
                        }
                        
                    }
                }
            }
            else
            {
                CheckBoxList2.Items.Clear();
                return;
            }
        }


注:在属性中已经指定每行12项/列

posted on 2016-09-02 18:51  代码养家 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wangzl1163/p/6341143.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值