c# 如何判断checkboxlist的某一项被选中,并取出值。

Wpenn_ 2012-04-19 09:56:31
string s = "";
for (int i = 0; i < checkboxlist.Items.Count; i++)
{
if (checkboxlist.Items[i].Selected == true)
{
s += checkboxlist.Items[i].Value+",";//取得值
}
}




这么写 为什么不对
...全文
1595 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

那我不会了 还是请高人指点吧
[/Quote]

谢谢 ~
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

是在什么时候做判断,取值的
[/Quote]


在页面加载的时候 把checklistbox里面的值给取出来
然后把它的值作为一个sql语句的参数 。
orochiheart 2012-04-19
  • 打赏
  • 举报
回复
那我不会了 还是请高人指点吧
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 4 楼 的回复:

引用 2 楼 的回复:

List<string> functionlist = new List<string>();
foreach (ListItem item in checkboxlist1.Items)
{
if (item.Selected)
functionlist……


这个方法写在页面加载的时候 所有的Item的sele……
[/Quote]


就是写在这个里面的 。
floweropen 2012-04-19
  • 打赏
  • 举报
回复
是在什么时候做判断,取值的
orochiheart 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用 2 楼 的回复:

List<string> functionlist = new List<string>();
foreach (ListItem item in checkboxlist1.Items)
{
if (item.Selected)
functionlist……


这个方法写在页面加载的时候 所有的Item的selected属性都是false。。
……
[/Quote]
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)//加层这个判断试试,不一定对 但感觉是你碰到了这个问题
{}
}
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C# code
string s = string.Empty;
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))//是否选中
……
[/Quote]

GetItemChecked 是什么方法 ?
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

List<string> functionlist = new List<string>();
foreach (ListItem item in checkboxlist1.Items)
{
if (item.Selected)
functionlist……
[/Quote]

这个方法写在页面加载的时候 所有的Item的selected属性都是false。。
不知道为什么 。
  • 打赏
  • 举报
回复
 string s = string.Empty;
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))//是否选中
{
s += checkedListBox1.Items[i].ToString();
}
}
orochiheart 2012-04-19
  • 打赏
  • 举报
回复
List<string> functionlist = new List<string>();
foreach (ListItem item in checkboxlist1.Items)
{
if (item.Selected)
functionlist.Add(item.Value);
}

functionlist 就是你选中项的集合
Wpenn_ 2012-04-19
  • 打赏
  • 举报
回复
upupupupup

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧