小编在做一个项目时被C# listbox双击难住了,虽然是很基础的内容,但是查到的信息不是很准确,我就只好集百家之鉴了,总结了一个准确的方法,来和大家分享。
- private void Page_Load(object sender, System.EventArgs e)
- {
- // 在此处放置用户代码以初始化页面
- if(!IsPostBack)
- {
- }
- if(!Page.IsStartupScriptRegistered("listbox1"))
- {
- ListBox_DblClick("listbox1",Page,ListBox1,"ListBox1","ListBox2");
- }
- if(!Page.IsStartupScriptRegistered("listbox2"))
- {
- ListBox_DblClick("listbox2",Page,ListBox2,"ListBox2","ListBox1");
- }
- }
下面是另一段代码,这是实现C# listbox双击的关键部分,好仔细研究哦!
- public void ListBox_DblClick(string Key,Page page,System.Web.UI.WebControls.WebControl webcontrol,
string RemoveListBox,string AddListBox)- {
- RemoveListBox = "document.Form1." + RemoveListBox;
- AddListBox = "document.Form1." + AddListBox;
- string mflistboxjs = " function change(RemoveListBox,AddListBox)" ;
- mflistboxjs += "{";
- mflistboxjs += "var addOption=document.createElement('option'); \n";
- mflistboxjs += "var index1; \n";
- mflistboxjs += "if(RemoveListBox.length==0)return(false);\n";
- mflistboxjs += "index1=RemoveListBox.selectedIndex; \n ";
- mflistboxjs += "if(index1<0)return(false);\n";
- mflistboxjs += "addOption.text=RemoveListBox.options(index1).text; \n";
- mflistboxjs += "addOption.value=RemoveListBox.value; \n";
- mflistboxjs += "AddListBox.add(addOption); \n";
- mflistboxjs += "RemoveListBox.remove (index1) \n";
- mflistboxjs +="}";
- mflistboxjs += "";
- page.RegisterStartupScript(Key,mflistboxjs);
- webcontrol.Attributes.Add("onDblClick","change(" + RemoveListBox + "," + AddListBox + ");");
- }
现在对怎么样实现C# listbox双击事件一目了然了吧!
【编辑推荐】
本文名称:浅析如何实现C#listbox双击事件
文章URL:http://www.csdahua.cn/qtweb/news37/369837.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网