C# 如何将双击事件添加到列表框

C# 如何将双击事件添加到列表框,c#,asp.net,listbox,C#,Asp.net,Listbox,我有一个asp列表框控件 <asp:ListBox ID="lstBox" runat="server" CssClass="listBox"></asp:ListBox> 我想在列表框中添加双击事件,我想弹出一个窗口。我在谷歌上搜索了一下,没有找到我的任何要求 是否存在捕获双击事件的事件。如果没有任何替代方案来实现这一点 顺便说一句,我想在服务器端完成所有工作,我正在网络表单中完成这项工作。我们在这里使用一个隐藏的输入字段来标识单击列表框的时间: <%@ Pag

我有一个asp列表框控件

<asp:ListBox ID="lstBox" runat="server" CssClass="listBox"></asp:ListBox>
我想在列表框中添加双击事件,我想弹出一个窗口。我在谷歌上搜索了一下,没有找到我的任何要求

是否存在捕获双击事件的事件。如果没有任何替代方案来实现这一点


顺便说一句,我想在服务器端完成所有工作,我正在网络表单中完成这项工作。我们在这里使用一个隐藏的输入字段来标识单击列表框的时间:

<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e){
if(Request.Params["ListBox1Hidden"] != null
&& (string)Request.Params["ListBox1Hidden"] == "doubleclicked") {
//This means It was double click
Response.Write("Double Click was fired selected item is " 
+ ListBox1.SelectedItem.Text);
   }
}

 </script>
<html>
<head>

<title></title>
<script lang="javascript">
    function ListBox1_DoubleClick() {
        /* we will change value of this hidden field so 
                 that in 
                 page load event we can identify event.
                        */

        document.forms[0].ListBox1Hidden.value = "doubleclicked";
        document.forms[0].submit();
    }
</script>
</head>
<body>
<form id="Form1" runat="server">

        <asp:ListBox id="ListBox1" 
                ondblclick="ListBox1_DoubleClick()" runat="server">
            <asp:ListItem Value="1">One</asp:ListItem>
            <asp:ListItem Value="2">Two</asp:ListItem>
            <asp:ListItem Value="3">Three</asp:ListItem>
            <asp:ListItem Value="4">Four</asp:ListItem>
        </asp:ListBox>
        <input type="hidden" name="ListBox1Hidden" />



</form>

您可以将页面加载时的双击事件添加到列表框中,并可以检测页面加载时的双击,如下代码所示

<asp:ListBox ID="lstitem" runat="server"></asp:ListBox>

你想通过单击鼠标右键来选择项目吗?不是所选项目,当我双击时,我只想打开一个弹出窗口。请查看我的答案。它没有鼠标双击事件@Slashy@hachitti等待您只想在它之后显示一个弹出窗口吗?为什么要使用javascript来实现这一点?在这种情况下,javascript方法会有所帮助吗?我想向其中添加一些数据,我想在服务器端@SlashyI告诉过你我想在我的cs页面上而不是在我的aspx上进行@Slashy@hachitti但它是服务器端,您可以从函数void Page_Load获取数据。。
 protected void Page_Load(object sender, EventArgs e)
            { 
               if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "lstdbclick")
                {
                   //your popup code here
                }
                lstitem.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(lstitem, "lstdbclick"));
            }