淺析如何實現C# listbox雙擊事件
作者:╃小〥斌╄
小編在做一個項目時被c# listbox雙擊難住了,雖然是很基礎的內容,但是查到的信息不是很準確,我就只好集百家之鑒了,總結了一個準確的方法,來和大家分享。
小編在做一個項目時被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 = "";
- page.RegisterStartupScript(Key,mflistboxjs);
- webcontrol.Attributes.Add("onDblClick","change(" + RemoveListBox + "," + AddListBox + ");");
- }
現在對怎么樣實現C# listbox雙擊事件一目了然了吧!
【編輯推薦】
責任編輯:阡陌
來源:
博客園