asp.net中的ListBox控件添加双击事件
问题:在Aspx页里的ListBox A中添加双击事件,将选中项添加到另一个ListBox B中,双击ListBox B中的选中项,删除当前选中项
页面:
<asp:ListBox ID="ListUsers" runat="server" Height="313px" SelectionMode="Multiple" Width="185px" ></asp:ListBox> <asp:ListBox ID="ListSelectedUsers" runat="server" Height="313px" SelectionMode="Multiple" Width="199px" "></asp:ListBox> <asp:TextBox ID="SelectedMode" runat="server" Style="display: none"></asp:TextBox>
JS 脚本:
function SelectOne() {
var lst1 = window.document.getElementById("ListUsers");
var lstindex = lst1.selectedIndex;
if (lstindex < )
return;
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
var lst2 = window.document.getElementById("ListSelectedUsers");
var mode = window.document.getElementById("SelectedMode");
if (mode.value == "True") { //如果是单值,先删除所有
for (var i = lst2.options.length - ; i >= ; i--) {
lst2.remove(i);
}
lst2.add(new Option(t, v, true, true), );
} else{
var isExists = false;
for (var i = ; i < lst2.options.length; i++) {
if (lst2.options[i].value == v) { //防止添加重复项
isExists = true;
break;
}
}
if (!isExists) {
lst2.options[lst2.options.length] = new Option(t, v, true, true);
}
}
}
//选择一条数据删除
function DelOne() {
var lst = window.document.getElementById("ListSelectedUsers");
var lstindex = lst.selectedIndex;
if (lstindex >= ) {
var v = lst.options[lstindex].value + ";";
lst.options[lstindex].parentNode.removeChild(lst.options[lstindex]);
}
}
后台代码:
if (!IsPostBack)
{
ListBoxBand();
SelectedMode.Text = "True";
ListUsers.Attributes.Add("onDblClick", "SelectOne()");//双击事件
ListSelectedUsers.Attributes.Add("onDblClick", "DelOne()");//双击事件
} private void ListBoxBand()
{ for (int i = ; i < ; i++)
{
ListUsers.Items.Add(new ListItem("Index" + i, i.ToString()));
}
}
效果:

asp.net中的ListBox控件添加双击事件的更多相关文章
- ASP.NET中 WebForm 窗体控件使用及总结【转】
原文链接:http://www.cnblogs.com/ylbtech/archive/2013/03/06/2944675.html ASP.NET中 WebForm 窗体控件使用及总结. 1.A, ...
- (转)客户端触发Asp.net中服务端控件事件
第一章. Asp.net中服务端控件事件是如何触发的 Asp.net 中在客户端触发服务端事件分为两种情况: 一. WebControls中的Button 和HtmlControls中的Type为su ...
- 在C#中使用属性控件添加属性窗口
转自原文 在C#中使用属性控件添加属性窗口 第一步,创建在应用程序中将要展现的字段属性为public公有属性.其中,所有的属性必须有get和set的方法(如果不设置get方法,则要显示的属性不会显示在 ...
- MFC中关于CListBox控件添加水平滚动条
首先是设置listbox控件的属性 Horizontal Scroll设为TRUE: 然后添加函数到CUighurRecognitionDlg.cpp(在CUighurRecognitionDlg. ...
- winform自定义控件中其他遮挡控件点击事件
自定义控件在其他窗口调用时,里面的lable阻挡了控件的点击事件 解决方法 自定义控件中lable的 点击事件 private void Lable1_Click(object sender, Eve ...
- 自动为DEV GridView控件添加SizeChanged事件
实现gdv设置的抽象对象,不用每个gdv控件都添加sizechanged事件,只需执行gdc绑定sql函数,在其中会自动添加SizeChanged事件. //2016.5.13 by sngk //根 ...
- ASP.NET中的chart控件绑定SQL Server数据库
网上很多的chart控件的实例都没有绑定数据库,经过一番摸索后,终于实现了chart控件绑定数据库. 首先,在Visual Studio中建立一个网站,新建一个WebForm项目,名称为ChartTe ...
- asp.net中的GridView控件的部分知识点
<PagerTemplate> <br /> <asp:Label ID="lblPage" runat="server" Tex ...
- ASP.NET中的验证控件
ASP.NET提供了如下的控件: RequiredFieldValidator: 字段必填 (ControlTovalidate设定要验证的控件) RangeValidator: 值在给定的最大值,最 ...
随机推荐
- [BZOJ 3123]森林
这题和 COT1 一定有 JQ 喵~ 线段树的启发式合并,每次要连接两个点时就对比较小的那棵树暴力 DFS 一边 然后均摊时间依旧是 logn 的,均摊真是世界上最邪恶的东西了…… 然后这题的数据是要 ...
- php区分new static 和new self
关键点在于一个是静态绑定,一个是延迟绑定 <?php class A{ public function __construct() { } public function createObjSt ...
- node.js环境安装,及连接mongodb测试
1.node.js环境安装 npm config set python python2.7npm config set msvs_version 2013npm config set registry ...
- 使用 openssl 生成证书
一.openssl 简介 目前最流行的 SSL 密码库工具官网:https://www.openssl.org/source/ 构成部分 密码算法库 密钥和证书封装管理功能 SSL通信API接口 用途 ...
- Eclipse启动tomcat时出现报错-拒绝访问
今天新建项目,当选择项目的发布路径为tomcat的路径时 启动tomcat出现如下错误: Publishing the configuration... Error copying file to D ...
- Nginx泛解析的匹配域名绑定到子目录配置
网站的目录结构为: # tree /home/wwwroot/linuxeye.com /home/wwwroot/linuxeye.com ├── bbs │ └── index.html └─ ...
- if、if elif判断
1.if.py #coding=utf-8 user = 'alex' passwd = 'alex3714' username = input('username:') password = inp ...
- Windows 查看端口占用和关闭进程
支持原创地址 :http://www.cnblogs.com/moodlxs/p/4145384.html 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PI ...
- oracle中找出某个字段中有非数字型的记录
工作中遇到一个大表记录中有非法非数字字符,不想用正则语法去做, 用一条SQL语句查出来的方法如下: select * from table where translate(col,'*01234567 ...
- Android基础之Activity四种启动模式
这东西是最基础的,发现自己其实没有真正试过,好好研究研究 standard :默认, singleTop :大体上同standard,但是当该Activity实例已经在task栈顶,不再创建新的实例, ...