效果如图:
前台页面插入
<asp:CheckBoxList ID="bandList" runat="server" RepeatDirection="Horizontal"(控制是水平排列还是竖直排列)>
</asp:CheckBoxList>
后台代码:
string str = "select brandID,brandname from xxxx";
DataSet ds = ConnDB(str);
foreach (DataRow row in ds.Tables[0].Rows)
{
string brandId = row[0].ToString();
string brandName = row[1].ToString();
/******************************/
ListItem newItem = new ListItem();
newItem.Text = brandName;
newItem.Value = brandId;
bandList.Items.Add(newItem);
}
dbHelper