小编在做一个项目时被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双击事件一目了然了吧!
【编辑推荐】