如何将双击鼠标事件添加到列表框?

How to add Double Click mouse event to listbox?(如何将双击鼠标事件添加到列表框?)
本文介绍了如何将双击鼠标事件添加到列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向列表框添加双击鼠标事件.当我双击一个项目时,我想获取特定项目并分配一个方法.我一直在寻找该领域的教程,但尝试过但不知何故不起作用.

感谢您的帮助!

解决方案

<%@ Page Language="C#" %><script runat="server">void Page_Load(对象发送者,EventArgs e){if(Request.Params["ListBox1Hidden"] != null&&(字符串)Request.Params[ListBox1Hidden"] ==双击"{//这意味着这是双击Response.Write("双击被触发所选项目是"+ ListBox1.SelectedItem.Text);}}void Button1_Click(对象发送者,EventArgs e){Response.Write("按钮被点击");}<头><脚本语言="javascript">函数 ListBox1_DoubleClick() {/* 我们将改变这个隐藏字段的值在页面加载事件我们可以识别事件.*/document.forms[0].ListBox1Hidden.value = "双击";document.forms[0].submit();}<身体><form runat="服务器"><div>双击列表框<br/><asp:ListBox id="ListBox1"ondblclick="ListBox1_DoubleClick()" runat="server"><asp:ListItem Value="1">一个</asp:ListItem><asp:ListItem Value="2">两个</asp:ListItem><asp:ListItem Value="3">三</asp:ListItem><asp:ListItem Value="4">四</asp:ListItem></asp:ListBox><input type="hidden" name="ListBox1Hidden"/>

<div>点击按钮<br/><asp:Button id="Button1" onclick="Button1_Click"runat="服务器" 文本="按钮"/>

</表单>

I would like to add a double click mouse event to a listbox. When I double click an item I'd like to get the specific item and assign a method. I have been searching for tuturials in this field, but tried but somehow wasn't working.

Thank you for helping !

解决方案

<%@ 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);
   }
}
void Button1_Click(object sender, EventArgs e) {
   Response.Write("Button was clicked");
}
</script>
<html>
<head>
    <script language="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 runat="server">
        <div>Double click on Listbox
            <br />
            <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" />
        </div>
        <div>click on button
            <br />
            <asp:Button id="Button1" onclick="Button1_Click" 
                runat="server" Text="Button"/>
        </div>
    </form>
</body>
</html>

这篇关于如何将双击鼠标事件添加到列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)