CheckBoxList控件
页面:
<asp:Panel ID="pLanguage" CssClass="panelLanguage" runat="server">
<asp:CheckBoxList ID="cblLanguage" RepeatLayout="Flow"
DataSourceID="odsLanguage" DataTextField="Name" DataValueField="LanguageID"
runat="server" AutoPostBack="True">
</asp:CheckBoxList>
</asp:Panel>
说明:
RepeatLayout=“FLow”设置CheckBoxList使用Span在页面呈现,另一个属性是"Table",设置外观为表格显示。使用Panel是为了实现类似ListBox的外观效果。可使用CSS代码控制Panel的外观:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
数据库绑定同DropDownList等控件。这里使用了ObjectDataSource控件绑定。
获取CheckBoxList选中的值:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
List<int> languageList = new List<int>();
if (cblLanguage != null)
{
foreach (ListItem item in cblLanguage.Items)
{
if (item.Selected)
{
languageList.Add(Convert.ToInt32(item.Value));
}
}
}
if (cblLanguage != null)
{
foreach (ListItem item in cblLanguage.Items)
{
if (item.Selected)
{
languageList.Add(Convert.ToInt32(item.Value));
}
}
}
读取数据库内容,并赋值
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
作者:苍苔
出处:http://www.cnblogs.com/WindWing/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。