本文介绍了如何将双击鼠标事件添加到列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想向列表框添加双击鼠标事件.当我双击一个项目时,我想获取特定项目并分配一个方法.我一直在寻找该领域的教程,但尝试过但不知何故不起作用.
感谢您的帮助!
解决方案
<%@ 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>
这篇关于如何将双击鼠标事件添加到列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!