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>
这篇关于如何将双击鼠标事件添加到列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将双击鼠标事件添加到列表框?
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
