<%@ Page Language="C#" AutoEventWireup="true" CodeFile="X200906021128.aspx.cs" Inherits="ListBoxs_X200906021128" %>
<!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>
<script type="text/javascript">
function MoveUP(fElement)
{
if (fElement.options.length == 0 || fElement.options[0].selected) return;
for (var i = 1; i < fElement.options.length; i++)
{
if (fElement.options[i].selected)
{
var text = fElement.options[i].text;
var value = fElement.options[i].value;
var selected = fElement.options[i].selected; fElement.options[i].text = fElement.options[i - 1].text;
fElement.options[i].value = fElement.options[i - 1].value;
fElement.options[i].selected = fElement.options[i - 1].selected; fElement.options[i - 1].text = text;
fElement.options[i - 1].value = value;
fElement.options[i - 1].selected = selected;
}
}
} function MoveDown(fElement)
{
if (fElement.options.length == 0 || fElement.options[fElement.options.length - 1].Selected) return; for (var i = fElement.options.length - 1; i > -1; i--)
{
if (fElement.options[i].selected)
{
var text = fElement.options[i + 1].text;
var value = fElement.options[i + 1].value;
var selected = fElement.options[i + 1].selected; fElement.options[i + 1].text = fElement.options[i].text;
fElement.options[i + 1].value = fElement.options[i].value;
fElement.options[i + 1].selected = fElement.options[i].selected; fElement.options[i].text = text;
fElement.options[i].value = value;
fElement.options[i].selected = selected;
}
}
} </script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="fListBox" runat="server" Height="200px" SelectionMode="Multiple" Width="200px"></asp:ListBox>
<br />
<br />
--- Server Side ------------------------------------------------------
<br />
<br />
<asp:Button ID="btnUp" runat="server" onclick="btnUp_Click" Text="Up" />
<asp:Button ID="btnDown" runat="server" onclick="btnDown_Click" Text="Down" />
<br />
<br />
--- Client Side ------------------------------------------------------
<br />
<br />
<input type="button" value="UP" onclick="MoveUP(document.getElementById('fListBox'));" />
<input type="button" value="Down" onclick="MoveDown(document.getElementById('fListBox'));" />
<br />
用 Ctrl + 鼠标 或 Ctrl + Shift 鼠标,实现多选或间断多选
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class ListBoxs_X200906021128 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < 20; i++)
fListBox.Items.Add(i.ToString());
}
} protected void btnUp_Click(object sender, EventArgs e)
{
// 没有项,或第一个选中节点已经是第一项,则不处理
if (this.fListBox.Items.Count == 0 || this.fListBox.Items[0].Selected) return;
for (int i = 1; i < this.fListBox.Items.Count; i++)
{
if (this.fListBox.Items[i].Selected)
this.ChangeProperty(this.fListBox.Items[i - 1], this.fListBox.Items[i]);
}
} protected void btnDown_Click(object sender, EventArgs e)
{
// 没有项,或最后一个选中节点已经是第一项,则不处理
if (this.fListBox.Items.Count == 0 || this.fListBox.Items[this.fListBox.Items.Count - 1].Selected) return;
for (int i = this.fListBox.Items.Count-1; i >-1 ; i--)
{
if (this.fListBox.Items[i].Selected)
this.ChangeProperty(this.fListBox.Items[i], this.fListBox.Items[i+1]);
}
} private void ChangeProperty(ListItem fFront, ListItem fCurrent)
{
string fText = fFront.Text;
string fValue = fFront.Value;
bool fSelected = fFront.Selected; fFront.Text = fCurrent.Text;
fFront.Value = fCurrent.Value;
fFront.Selected = fCurrent.Selected; fCurrent.Text = fText;
fCurrent.Value = fValue;
fCurrent.Selected = fSelected;
}
}

listbox多选实现上下移动 js版和服务器版的更多相关文章

  1. Ubuntu桌面版与服务器版有什么不同?

         提到安装Linux,Ubuntu可谓是最受欢迎的.为了满足每个人的需求,出现了不少版本或风格的Ubuntu;其中两项便是桌面版与服务器版.只要发布版本号一致,这两者从核心来说也就是相同的,唯 ...

  2. Ubuntu桌面版与服务器版的区别(转)

    Ubuntu桌面版vs服务器版 提到安装Linux,Ubuntu可谓是最受欢迎的.为了满足每个人的需求,出现了不少版本或风格的Ubuntu:其中两项便是桌面版与服务器版.只要发布版本号一致,这两者从核 ...

  3. 微信支付开发(1) JS API支付V3版(转)

    http://www.cnblogs.com/txw1958/p/wxpayv3-jsapi.html 本文介绍微信支付下的jsapi实现流程 前言 微信支付现在分为v2版和v3版,2014年9月10 ...

  4. ListBox复选框拓展

    Toolkit的LongListMutiSelector的复选框功能,想必许多人都需要吧!然而系统本身控件ListBox虽然也有多选功能,可是外观上却缺乏复选框,选择效果只是颜色变化.于是在上一个项目 ...

  5. js操作文件 HTML5版

    js操作文件 HTML5版,有需要的朋友可以参考下. <!DOCTYPE html> <html> <head> <title>JSFileReader ...

  6. 你不知道的 JS (系列丛书) - 第二版

    你不知道的 JS (系列丛书) - 第二版 You Don't Know JS (book series) - 2nd Edition https://github.com/learning-js-b ...

  7. 使用 js 实现一个简易版的模版引擎

    使用 js 实现一个简易版的模版引擎 regex (function test() { this.str = str; })( window.Test = ...; format() { let ar ...

  8. 使用 js 实现一个简易版的 drag & drop 库

    使用 js 实现一个简易版的 drag & drop 库 具有挑战性的前端面试题 H5 DnD js refs https://www.infoq.cn/article/0NUjpxGrqRX ...

  9. 使用 js 实现一个简易版的动画库

    使用 js 实现一个简易版的动画库 具有挑战性的前端面试题 animation css refs https://www.infoq.cn/article/0NUjpxGrqRX6Ss01BLLE x ...

随机推荐

  1. X Window System介绍

    1.概述     X Window System是1984年由麻省理工学院(MIT)和DEC公司共同开发研究的,是执行在UNIX系统上的视窗系统.严格地说,X Window System并非一个软件, ...

  2. C#堆栈

    栈就是堆栈,因为堆和堆栈这样说太拗口了,搞得像绕口令,所以有些时候就把堆栈简称为栈.堆和栈,你看这又多舒服. 但无论什么时候,堆栈都不等于堆和栈,必须说,堆和栈或者堆和堆栈. 有人说:“C#的所有值类 ...

  3. Cin、Cout 加快效率方法

    std::ios::sync_with_stdio(false); 在main 函数中加上这么一句话. 可以打消iostream的输入输出缓存,可以节省许多时间,使效率与scanf与printf相差无 ...

  4. POJ 2208 Pyramids 欧拉四面体

    给出边长,直接就可以求出体积咯 关于欧拉四面体公式的推导及证明过程 2010-08-16 14:18 1,建议x,y,z直角坐标系.设A.B.C少拿点的坐标分别为(a1,b1,c1),(a2,b2,c ...

  5. ORACLE存储过程笔记1

    ORACLE存储过程笔记1 一.基本语法(以及与informix的比较)   create [or replace] procedure procedure_name (varible {IN|OUT ...

  6. Android学习笔记:使用ViewPager组件实现图片切换

    在很多App中,尤其是第一次安装启动后,都会出现几个图片进行一些app的介绍和说明,图片可以随着滑动而切换. 我们这里利用 ViewPager组件来演示如何实现这一点. 1.创建一个app工程,默认创 ...

  7. php calling scope

    昨天在Yaf交流群, 大草原同学批评我变懒了, Blog很久没更新了, 今天刚好有人在Segmentfalut上问了我一个问题,  我在微博上也做了简单的解答, 不过感觉一句话说不清楚, 就写篇blo ...

  8. yii框架网址解析问题

    转载请注明来自souldak,微博:@evagle 首先如果你在config/main.php里面没有配置urlManager的话,那么流程如下(摘自yii官网) 用户发出了访问 URL http:/ ...

  9. win7下wordPress本地搭建博客详解(深度亲测整理---傻瓜式详细教程)

    搭建一个wordPress作为一个个人博客本来是特别简单的事情,但是网上的各种转载让初学者举步维艰,我就本身条件而言,会java EE,懂mysql都花费了我好长时间才搭建好本地博客. 注意:这个是本 ...

  10. poj3308 Paratroopers --- 最小点权覆盖-&gt;最小割

    题目是一个非常明显的二分图带权匹配模型, 加入源点到nx建边,ny到汇点建边,(nx.ny)=inf建边.求最小割既得最小点权覆盖. 在本题中因为求的是乘积,所以先所有取log转换为加法,最后再乘方回 ...