<%@ 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. HDU 5281 Senior&#39;s Gun

    Senior's Gun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  2. leetcode_question_64 Minimum Path Sum

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  3. 典型c库函数的实现

    StrToInt:字符串转int输出 enum Status { kValid = , kInvalid = , }; int StrToInt(const char* str) { g_nStatu ...

  4. tomcat 系统服务 outofmemory

    TOMCAT内存溢出outofmemory的问题: http://hi.baidu.com/mefeng47/item/3b247af74ce4e24e922af2e5 注:双击tomcat6w.ex ...

  5. [Swust OJ 191]--迷宫逃离(打表搜索)

      题目链接:http://acm.swust.edu.cn/problem/191/ Time limit(ms): 1000 Memory limit(kb): 65535   江鸟突然想到了一个 ...

  6. [Swust OJ 585]--倒金字塔(LIS最长不下降子序列)

    题目链接:http://acm.swust.edu.cn/problem/585/ Time limit(ms): 3000 Memory limit(kb): 65535   SWUST国的一支科学 ...

  7. 2014 HDU多校弟五场J题 【矩阵乘积】

    题意很简单,就是两个大矩阵相乘,然后求乘积. 用 Strassen算法 的话,当N的规模达到100左右就会StackOverFlow了 况且输入的数据范围可达到800,如果变量还不用全局变量的话连内存 ...

  8. 人人都用 Retina 屏幕的 MacBook Pro 笔记本电脑

    自从今年年初 Apple 官网产品降价我立即买了 13 寸的 Retina 屏 MacBook Pro(rMBP)之后, 这款苹果的笔记本电脑就成了我在公司和家里的唯一电脑(就是这一款). 使用苹果的 ...

  9. 设计模式 ( 十三 ) 命令模式Command(对象行为型)

    设计模式 ( 十三 ) 命令模式Command(对象行为型) 1.概述         在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需 ...

  10. Effective C++ Item 40 明智而审慎地使用多重继承

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:多重继承比单一继承复杂.它可能导致新的歧义性,以及对 virtual 继承的须要 演示 ...