asp.net控件之ListBox
来源:互联网 发布:网络测速工具 编辑:程序博客网 时间:2024/05/16 07:44
在学习asp.net的ListBox控件时
当ListBox1插入到ListBox2中时
首先,应取出Listbox1中的item值,使用foreach遍历添加到ListBox2中
for (int i = 0; i < this.ListBox1.Items.Count; i++)
{
if (ListBox1.Items[i].Selected)
{
ListBox2.Items.Add(listby.Items[i]);
this. ListBox1.Items.Remove(listby.Items[i]);
}
}
此时并不能取出所有你选中的值,比如我们选中两项,这时根据索引进入for循环,当第一个元素被删除后,第二个元素的value属性值减一,所以找不到原来符合if条件的value所对应的项。所以应该使用倒遍历的方式
List<ListItem> list = new List<ListItem>();
for (int i = this. ListBox1.Items.Count - 1; i >= 0; i--)
{
if (ListBox1.Items[i].Selected == true)
{
list.Add(ListBox1.Items[i]);
this. ListBox1.Items.Remove(ListBox1.Items[i]);
}
}
再遍历item
- asp.net控件之ListBox
- asp.net ListBox控件基本功能
- Multi-ListBox ASP.NET控件
- 全面的asp.net listbox控件操作
- asp.net ListBox控件添加双击事件
- ASP.NET开发笔记之数据列表等控件选择【listbox VS gridview】
- ASP Web控件-----ListBox
- asp.net如何利用两个listbox控件做联动?
- ASP.NET - ListBox Web 服务器控件概述(上)
- ASP.NET - ListBox Web 服务器控件概述(下)
- asp.net中ListBox控件经典实例(反向遍历)
- ASP.NET之控件
- 自定义控件之ListBox
- mfc控件之ListBox
- MFC控件之ListBox
- MFC控件之ListBox
- VS.NET windows编程基础之ListBox控件的使用
- vb.net的ListBox控件
- C#之获取年、月、日、时、分、秒...
- 两个数组a[N],b[N],其中a[N]的各个元素值已知,现给b[i]赋值
- 主窗口技巧 (适用于SDI、MDI)
- POJ 1611 并查集水题
- eclipse 去掉 所有 断点
- asp.net控件之ListBox
- struct stat st 和 struct stat *st 两种定义方式区别
- 堆和栈的区别(转过无数次的文章)
- CKEditor 3.x 在Java中配置、包括图片上传、支持FTP、图片压缩
- 子网掩码的作用
- VC应用程序的退出
- Android实现微信底部的带消息提示数量
- Variable expansion Modifiers (parameter expansion)
- 配置Android开发环境常见错误解决办法(陆续添加)“your project contains error(s),please fix them before running your appli