惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - SysInfo

[转]一个利用Sql Server 20005的 ROW_NUMBER Function 的分页存储过程. 新域名注册成功.http://sysinfo.com.cn/ 如何在上传图片之前预览图片? - SysInfo - 博客园 asp.net执行.sql文件 - SysInfo - 博客园 The New Controls of ASP.NET 2.0 Installing the ASP.NET "Atlas" Wiki - SysInfo [转]常见的 Web 项目转换问题及解决方案 今天下午回家:提前给大家拜个年! [转]MSN消息提示类(纯js编写) - SysInfo - 博客园 window对象的status、location、name、self、opener属性的使用 RadioButton加入DataGrid模板列引起的问题。 疙瘩汤 NHibernate Response.BinaryWrite()下载时文件名的问题. 细说HTML元素的ID和Name属性的区别 收藏 用JavaScript解决ASP.NET服务器控件造成的刷新问题 子父窗口之间的操作之小例子 用实例说明如何用JavaScript生成XML
为.net中的ListBox控件添加双击事件
SysInfo · 2005-11-17 · via 博客园 - SysInfo

        我在用dotnet做一个项目的过程中,遇到了一个ListBox的问题:通过在一个ListBox中双击,把选中的项添加到另一个ListBox中,但ListBox控件本身并没有该事件,那么如何实现呢?我就想到了客户端脚本javascrit,通过查阅相关资料,终于把这个问题解决了,现在写出来与大家分享,希望能对大家有所帮助。
        这里有三个问题:
        第一:双击所要执行的javascript代码是什么?

 1                     function change()
 2                         {
 3                              var addOption=document.createElement("option");
 4                              var index1;
 5                              if(document.Form1.ListBox1.length==0)return(false);
 6                               index1=document.Form1.ListBox1.selectedIndex; 
 7                              if(index1<0)return(false);
 8                               addOption.text=document.Form1.ListBox1.options(index1).text;
 9                               addOption.value=document.Form1.ListBox1.value;
10                              document.Form1.ListBox2.add(addOption);
11                              document.Form1.ListBox1.remove (index1);
12                          }
13 

        第二:如何将 javas cript 代码转换为C#代码?

 1 public static void ListBox_DblClick(Page page,System.Web.UI.WebControls.WebControl webcontrol,string                                 SourceControlName,string TargetControlName)
 2                      {
 3                            SourceControlName = "document.Form1." +  SourceControlName;
 4                            TargetControlName = "document.Form1." +  TargetControlName;
 5                            string js = "<s cript language=javas cript> function change(SourceControlName,TargetControlName)";
 6                            js += "{";
 7                            js +=     "var addOption=document.createElement('option'); \n";
 8                            js += "  var index1; \n";
 9                            js += "if(SourceControlName.length==0)return(false);\n";
10                            js += "  index1=SourceControlName.selectedIndex; \n ";
11                            js += "  if(index1<0)return(false);\n";
12                            js += " addOption.text=SourceControlName.options(index1).text; \n";
13                            js += "addOption.value=SourceControlName.value; \n";
14                            js += "TargetControlName.add(addOption); \n";
15                            js += "SourceControlName.remove (index1) \n";
16                            js +="}";
17                            js += "</s cript>";
18                             //注册该 javas cript ;
19                            page.RegisterStartups cript("",js);
20                             //为控件添加双击事件;
21                            webcontrol.Attributes.Add("onDblClick","change(" + SourceControlName + "," + TargetControlName +                                 ");");
22                       }
23 
24 

            在该方法中,SourceControlName是要绑定双击事件的控件,TargetControlName是接收双击事件选定项的控件。    
            这里有一个问题,如何让对象作为参数传给javas cript的change函数,我这里采用的是用 SourceControlName  ,TargetControlName 来传递两个ListBox的Name, 然后与“document.Form1.“组合成一个串来传递给javas cript的change函数,即
                            SourceControlName = "document.Form1." +  SourceControlName;
                           TargetControlName = "document.Form1." +  TargetControlName;
        第三:如何为控件添加双击事件?
        用ControlName.Attributes.Add(“属性名称”,“函数名称或代码”);