CheckBoxList详细用法
来源:互联网 发布:魔术师生涯数据 编辑:程序博客网 时间:2024/05/16 18:45
1.绑定数据
this.lngCatalogID.DataSource = dt; //这里我绑到DataTable上了.
this.lngCatalogID.DataTextField = "strCatalogName"; //前台看到的值,也就是CheckBoxList中显示出来的值
this.lngCatalogID.DataValueField = "lngCatalogID"; //这个值直接在页面上是看不到的,但在源代码中可以看到
this.lngCatalogID.DataBind();
2.获取钩选的项
foreach(ListItem li in lngCatalogID.Items)
{
if(li.Selected) //表示某一项被选中了
{
//li.Test表示看到的值,对应上面的strCatalogName
//li.Value表示看到的值对应的值.对应上面的lngCatalogID
}
}
3.设置某项为钩选状态
foreach(ListItem li in lngCatalogID.Items)
{
if(li.Value.Equals("钩选条件")) //如果li.Value值等于某值,就钩选
{
li.Selected = true; //等于true就表示钩选啦.
break;
}
}
数据绑定
checkedListBox1.DataSource=ds.Tables[0];
checkedListBox1.ValueMember="intSectionID";
checkedListBox1.DisplayMember="txtShortDesc".ToString();
数据显示
int count = checkedListBox1.Items.Count;
for (int i = 0;i<count;i++)
{
if (checkedListBox1.GetItemChecked(i))
{
MessageBox.Show(checkedListBox1.Items[i].ToString());
}
}
DataGrid中全选
foreach(DataGridItem thisItem in DataGridLogininfo.Items)
{
((CheckBox)thisItem.Cells[0].Controls[1]).Checked = CheckBox2.Checked;
}
反向选择
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
checkedListBox1.SetItemChecked(i, false);
}
else
{
checkedListBox1.SetItemChecked(i, true);
}
}
- CheckBoxList详细用法
- CheckBoxList详细用法
- CheckBoxList详细用法
- CheckBoxList详细用法
- CheckBoxList用法
- CheckBoxList用法
- CheckBoxList控件基本用法
- checkboxlist控件用法
- [.NET]CheckBoxList 用法
- s:checkboxlist 用法
- checkboxlist标签的用法
- <asp:CheckBoxList>的用法
- Checkboxlist多选的用法
- struts2 checkboxlist标签使用的详细说明
- checkBoxList
- CheckBoxList
- CheckBoxList
- CheckBoxList
- 枚举进程(2)——利用EPROCESS/PEB地址特征进行内存搜索
- Injecting JNDI datasources for JUnit Tests outside of a container
- 常用软件测试类型分类讲解
- 0605周四
- [Singles]星外星2+1系列:半世纪的爵士情浓
- CheckBoxList详细用法
- 人品不行
- El Perro del Mar - From The Valley To The Stars
- 迷茫
- OleDbConnection 与 SqlConnection
- Since October - This Is My Heart
- BoBo族
- SF
- Haxe学习(1)