代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
.NET上下左右移动操作支持多选
作者:
冰薇
/ 发布于
2015/2/28
/
710
public partial class FieldShowSet : System.Web.UI.Page { Hashtable resources = EquStatusSearch.resources; private string names = null; IniOperation ini = new IniOperation("i18n"); Hashtable leftSelectItems = new Hashtable(); //左边选中项集合 Hashtable rightSelectItems = new Hashtable(); //右边选中项集合 protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { names = QuarrysClass.All; initi18n(); string[] all = string.IsNullOrEmpty(names) ? null : names.Split(',');//分割出所有列 hidfShows.Value = ini.IniValue("Set", "Show"); string include = hidfShows.Value;//获取当前页展示列 if (string.IsNullOrEmpty(names) || all == null) { //请先点加载配置信息 return; } for (int i = 0; i < all.Length; i++)//遍历所有列 { if (include.IndexOf("@" + all[i] + "@") == -1)//当前列中不包含分割出来的列时放在不显示框中 { leftListBox.Items.Add(new ListItem(resources[all[i]].ToString(), all[i])); } } string[] showNames = include.Split(','); string newName = string.Empty; foreach (string name in showNames) { newName = name.Trim('@'); string colName = resources[newName] == null ? string.Empty : resources[newName].ToString(); if (!string.IsNullOrEmpty(newName)) { rightListBox.Items.Add(new ListItem(colName, newName)); } } } } //调用显示和展示字段名称 private void initi18n() { this.Page.Title = string.IsNullOrEmpty(resources["ShowSetName"].ToString()) ? "字段显示设置" : resources["ShowSetName"].ToString(); xLabel1.Text = string.IsNullOrEmpty(resources["ShowSetNoShow"].ToString()) ? "不显示字段" : resources["ShowSetNoShow"].ToString(); xLabel2.Text = string.IsNullOrEmpty(resources["ShowSetShow"].ToString()) ? "显示字段" : resources["ShowSetShow"].ToString(); } //将未显示字段 右移 到显示字段框,并清除掉不显示的选择到的项 protected void rbtnMove_Click(object sender, EventArgs e) { if (leftListBox.SelectedItem == null) { return; } leftSelectItems.Clear(); foreach (ListItem item in leftListBox.Items) { if (item.Selected) { if (!leftSelectItems.ContainsKey(item.Value)) { leftSelectItems.Add(item.Value, item.Text); } } } foreach (DictionaryEntry v in leftSelectItems) { leftListBox.Items.Remove(new ListItem(v.Value.ToString(),v.Key.ToString())); rightListBox.Items.Add(new ListItem(v.Value.ToString(), v.Key.ToString())); } } //将显示字段 左移 到未显示字段框,并清除掉显示的选择到的项 protected void lbtnMove_Click(object sender, EventArgs e) { if (rightListBox.SelectedItem == null) { return; } rightSelectItems.Clear(); foreach (ListItem item in rightListBox.Items) { if (item.Selected) { if (!rightSelectItems.ContainsKey(item.Value)) { rightSelectItems.Add(item.Value, item.Text); } } } foreach (DictionaryEntry v in rightSelectItems) { rightListBox.Items.Remove(new ListItem(v.Value.ToString(), v.Key.ToString())); leftListBox.Items.Add(new ListItem(v.Value.ToString(), v.Key.ToString())); } } //将左边所有不显示项加到右边的显示项中 protected void btnAllLMove_Click(object sender, EventArgs e) { foreach (ListItem item in leftListBox.Items) { rightListBox.Items.Add(item); } leftListBox.Items.Clear(); } //将右边所有不显示项加到左边的显示项中 protected void btnAllRMove_Click(object sender, EventArgs e) { foreach (ListItem item in rightListBox.Items) { leftListBox.Items.Add(item); } rightListBox.Items.Clear(); } //点击设置按钮事件, protected void btnSet_Click(object sender, EventArgs e) { try { string str = ""; for (int i = 0; i < rightListBox.Items.Count; i++)//循环添加显示项组成字符串 { str += "@" + rightListBox.Items[i].Value + "@,"; } if ("".Equals(str))//如果显示项为空直接清除显示页面的所有字段 { QuarrysClass.Shows = ""; } else { //重新复制显示字段到显示页面 QuarrysClass.Shows = str.Substring(0, str.Length - 1); } //调用主页面将显示字段写入到i18n文件中 ini.IniWriteValue("Set", "Show", QuarrysClass.Shows); Page.ClientScript.RegisterStartupScript(this.GetType(), "warn", "alert('设置成功!');window.opener.searchData();window.close();", true); } catch (Exception ex) { string strScript = string.Format("alert('设置失败!{0}');", ex.Message); Page.ClientScript.RegisterStartupScript(this.GetType(), "warn", strScript, true); } } /*************************************************************************/ /// <summary> /// 得到选定项的值 /// </summary> /// <returns></returns> protected string[] getSelectedValue() { ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); string[] strs = new string[indices.Length]; for (int i = 0; i < indices.Length; i++) { strs[i] = rightListBox.Items[indices[i]].Value; } return strs; } /// <summary> /// 得到选定项的内容 /// </summary> /// <returns></returns> protected string[] getSelectedText() { ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); string[] strs = new string[indices.Length]; for (int i = 0; i < indices.Length; i++) { strs[i] = rightListBox.Items[indices[i]].Text; } return strs; } //上移 protected void btnUp_Click(object sender, EventArgs e) { UpMove(); } //下移 protected void btnDown_Click(object sender, EventArgs e) { DownMove(); } void UpMove() { if (rightListBox.SelectedIndex > 0) { string[] newValue = getSelectedValue(); string[] newText = getSelectedText(); ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); for (int i = 0; i < indices.Length; i++) { int newIndex = indices[i]; //交换位置 rightListBox.Items[newIndex].Value = rightListBox.Items[newIndex - 1].Value; rightListBox.Items[newIndex].Text = rightListBox.Items[newIndex - 1].Text; rightListBox.Items[newIndex - 1].Value = newValue[i]; rightListBox.Items[newIndex - 1].Text = newText[i]; rightListBox.Items[newIndex - 1].Selected = true; rightListBox.Items[newIndex].Selected = false; } rightListBox.Items[indices[indices.Length - 1]].Selected = false; } } void DownMove() { string[] newValue = getSelectedValue(); string[] newText = getSelectedText(); ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); if (indices[a.Count - 1] < rightListBox.Items.Count - 1) //选中项的最大索引小于列表总项数 { for (int i = indices.Length - 1; i >= 0; i--) { int newIndex = indices[i]; //交换位置 rightListBox.Items[newIndex].Value = rightListBox.Items[newIndex + 1].Value; rightListBox.Items[newIndex].Text = rightListBox.Items[newIndex + 1].Text; rightListBox.Items[newIndex + 1].Value = newValue[i]; rightListBox.Items[newIndex + 1].Text = newText[i]; rightListBox.Items[newIndex + 1].Selected = true; rightListBox.Items[newIndex].Selected = false; } rightListBox.Items[indices[0]].Selected = false; } } void TopMove() { string[] newValue = getSelectedValue(); string[] newText = getSelectedText(); ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); for (int i = 0; i < indices.Length; i++) { int newIndex = indices[i]; for (int j = newIndex - 1; j >= 0; j--) { rightListBox.Items[j + 1].Text = rightListBox.Items[j].Text; rightListBox.Items[j + 1].Value = rightListBox.Items[j].Value; } rightListBox.Items[0].Value = newValue[indices.Length - 1 - i]; rightListBox.Items[0].Text = newText[indices.Length - 1 - i]; rightListBox.Items[newIndex].Selected = false; rightListBox.Items[i].Selected = true; } } void BottomMove() { string[] newValue = getSelectedValue(); string[] newText = getSelectedText(); ArrayList a = new ArrayList(); for (int i = 0; i < rightListBox.Items.Count; i++) { if (rightListBox.Items[i].Selected) { a.Add(i); } } int[] indices = new int[a.Count]; //得到选中项的索引集合 a.CopyTo(indices); for (int i = indices.Length - 1; i >= 0; i--) { int newIndex = indices[i]; //获取总的数目 int newCount = rightListBox.Items.Count; for (int j = newIndex; j < newCount - 1; j++) { rightListBox.Items[j].Text = rightListBox.Items[j + 1].Text; rightListBox.Items[j].Value = rightListBox.Items[j + 1].Value; } rightListBox.Items[newCount - 1].Value = newValue[indices.Length - 1 - i]; rightListBox.Items[newCount - 1].Text = newText[indices.Length - 1 - i]; rightListBox.Items[newIndex].Selected = false; rightListBox.Items[newCount - 1 - (indices.Length - 1 - i)].Selected = true; } } protected void btnTop_Click(object sender, EventArgs e) { TopMove(); } protected void btnBottom_Click(object sender, EventArgs e) { BottomMove(); } }
试试其它关键字
多选
移动
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
冰薇
贡献的其它代码
(
2
)
.
操作windows服务
.
.NET上下左右移动操作支持多选
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3