asp.net中ListBox控件经典实例(反向遍历)
来源:互联网 发布:战锤全面战争淘宝 编辑:程序博客网 时间:2024/05/29 16:35
.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBox控件.aspx.cs" Inherits="ListBox控件" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <p2>ListBox控件练习:<br /> </p2> <asp:ListBox ID="ListBox1" runat="server" Height="76px" SelectionMode="Multiple" style="margin-right: 17px" Width="88px" > <asp:ListItem>1</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>4</asp:ListItem> <asp:ListItem>5</asp:ListItem> <asp:ListItem>6</asp:ListItem> <asp:ListItem>7</asp:ListItem> <asp:ListItem>8</asp:ListItem> <asp:ListItem>9</asp:ListItem> </asp:ListBox> <asp:Button ID="Button1" runat="server" Text="选择" onclick="Button1_Click" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> 点菜程序<br /> <asp:ListBox ID="ListBox2" runat="server" Height="184px" SelectionMode="Multiple" style="margin-right: 17px" Width="131px" > <asp:ListItem>鱼香茄子</asp:ListItem> <asp:ListItem>辣子鸡</asp:ListItem> <asp:ListItem>酸菜鱼</asp:ListItem> <asp:ListItem>酸辣土豆丝</asp:ListItem> <asp:ListItem>麻婆豆腐</asp:ListItem> <asp:ListItem>蜀山烤鱼</asp:ListItem> <asp:ListItem>宫保鸡丁</asp:ListItem> <asp:ListItem>土豆牛腩</asp:ListItem> <asp:ListItem>红烧肉</asp:ListItem> </asp:ListBox> <asp:Button ID="Button3" runat="server" Text="选择" onclick="Button3_Click" /> <asp:Button ID="Button2" runat="server" Text="移除" onclick="Button2_Click" /> <asp:ListBox ID="ListBox3" runat="server" Height="184px" SelectionMode="Multiple" style="margin-right: 17px" Width="131px" > </asp:ListBox> </div> </form></body></html>
.aspx.cs代码如下:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class ListBox控件 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { TextBox1.Text = ""; // for (int i = 0; i < ListBox1.Items.Count; i++) { // if (ListBox1.Items[i].Selected) { TextBox1.Text += ListBox1.Items[i].Text+","; } // } foreach (ListItem _li in ListBox1.Items) { if (_li.Selected) { TextBox1.Text += _li.Text; } } } protected void Button3_Click(object sender, EventArgs e)//为什么要用反向遍历,要注意!!!!!! { for (int i = ListBox2.Items.Count - 1; i >= 0; i--) { if (ListBox2.Items[i].Selected) { ListBox3.Items.Add(ListBox2.Items[i]); ListBox2.Items.Remove(ListBox2.Items[i]); } } } protected void Button2_Click(object sender, EventArgs e) { for (int i = ListBox3.Items.Count - 1; i >= 0; i--) { if (ListBox3.Items[i].Selected) { ListBox2.Items.Add(ListBox3.Items[i]);//添加功能 ListBox3.Items.Remove(ListBox3.Items[i]);//移除功能 } } }}
效果如下:
0 0
- asp.net中ListBox控件经典实例(反向遍历)
- asp.net ListBox控件基本功能
- Multi-ListBox ASP.NET控件
- asp.net控件之ListBox
- ASP.NET - ListBox Web 服务器控件概述(上)
- ASP.NET - ListBox Web 服务器控件概述(下)
- 遍历网页中所有的控件(asp.net)
- ASP.NET(C#)中遍历所有控件
- ASP.NET(C#)中遍历所有控件
- 全面的asp.net listbox控件操作
- asp.net ListBox控件添加双击事件
- asp.net遍历控件
- ASP.NET 控件遍历
- asp.net中dropdownlist控件实例操作
- ASP.net中使用ListBox一点经验
- asp.net 中listbox 中的项删除
- Asp.net 中listbox 滚动条定位
- Asp.net中ListBox的用法!
- ubuntu在ping运行时终端回显特别慢,但实际数据包time值并不大的解决方法(转)
- Get process name from application name and vice versa, using Applescript
- Spark技术内幕: Shuffle详解(一)
- 关于伪类的使用的一些心得以及星星评分效果的实现
- Oracle OCP笔记(01)数据库体系结构概要
- asp.net中ListBox控件经典实例(反向遍历)
- linux X界面 输入密码正确,但是无法登陆系统,命令行界面可以登陆
- VirtualBox:Fatal:Could not read from Boot Medium! System Halted解决措施
- java中注解的使用与实例(一)
- HDU 2035 人见人爱A^B
- SpringMVC+Spring3+Hibernate4开发环境搭建
- Android中的各种loading
- High-Performance Server Architecture
- URAL 2018 The Debut Album(dp)