CheckBoxList定義每行個數後,自動換行
阿新 • • 發佈:2019-02-19
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項/列