| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 784 人关注过本帖
标题:关于ListBox的问题
只看楼主 加入收藏
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
结帖率:98.25%
收藏
 问题点数:0 回复次数:7 
关于ListBox的问题
我想用ListBox实现选择多项内容进行查询的功能,现在已经知道SelectionMode可以设置多项选择,但是不知道怎么能取到这些值,用
Response.Write(listBox.SelectedValue);
只能打出所选项目中的第一个值,请问怎么才能我所选择的全部项呢?
研究多日未果,谢谢各位了先。
搜索更多相关主题的帖子: ListBox Response Write listBox 项目 
2006-01-18 15:24
huoshanhui
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-12-5
收藏
得分:0 

选择的项在ListBox.SelectedItems中
ArrayList temp=new ArrayList();
for(int i=0;i<this.listBox1.SelectedItems.Count;i++)
{
temp.Add(this.listBox1.SelectedItems[i]);
}


2006-01-18 15:35
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
E:\LawContract\Contract_1\contractStatistical.aspx.cs(134): “System.Web.UI.WebControls.ListItem”并不包含对“Count”的定义

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-18 16:35
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
虽然现在还是没弄明白,但还是谢谢2楼回答

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-18 16:50
huoshanhui
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-12-5
收藏
得分:0 

你要早说是web下的啊,我还以为是form下的呢
在web下的话遍历所有item,判断是否被选择了,然后挑出
ArrayList temp=new ArrayList();
for(int i=0;i<this.ListBox1.Items.Count;i++)
{
if(this.ListBox1.Items[i].Selected==true)
temp.Add(this.ListBox1.Items[i]);
}


2006-01-18 17:07
huoshanhui
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-12-5
收藏
得分:0 
用foreach也行:
ArrayList temp=new ArrayList();
foreach(ListItem li in ListBox1.Items)
{
if(li.Selected == true)
temp.Add(this.ListBox1.Items[i]);
}

2006-01-18 17:25
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
好的,我先试试,没说明白,这是我的错

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-18 17:27
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 

我弄明白了, 非常感谢huoshanhui


本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2006-01-18 18:04
快速回复:关于ListBox的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013384 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved