ASP.NET中ListBox实现Double Click事件
2009-11-10 16:50:21 来源:WEB开发网核心提示:(1)在WEB页面上加入JS脚本和存放ListBox事件的隐藏输入框,LISTBOX是用来保存时间的名称,在CS页面用到:其JS代码如下:<script language="javascript"> function ListBox1_DoubleClick() { /* we will
(1)在WEB页面上加入JS脚本和存放ListBox事件的隐藏输入框,LISTBOX是用来保存时间的名称,在CS页面用到:其JS代码如下:
<script language="javascript">
function ListBox1_DoubleClick() {
/* we will change value of this hidden field so that inpage load event we can identify event.
*/
document.forms[0].ListBox1Hidden.value = "doubleclicked";
document.forms[0].submit();
}
</script>
(2)将asp.net控件LISTBOX中加入双击事件声明如下:
<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>
(3)在WEB窗体加载的时候执行如下代码(即双击LISTBOX中ITEM后执行的内容),
if(Request.Params["ListBox1Hidden"] != null
&& (string)Request.Params["ListBox1Hidden"] == "doubleclicked" )
{
//the Listwas double click Event
}
}
例子如下:
<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>WEB窗体加载时候执行下列代码就能实现双击ListBox中Item执行一些操作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 language="javascript">
function ListBox1_DoubleClick() {
/* we will change value of this hidden field so that inpage load event we can identify event.
*/
document.forms[0].ListBox1Hidden.value = "doubleclicked";
document.forms[0].submit();
}
</script>
(2)将asp.net控件LISTBOX中加入双击事件声明如下:
<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>
(3)在WEB窗体加载的时候执行如下代码(即双击LISTBOX中ITEM后执行的内容),
if(Request.Params["ListBox1Hidden"] != null
&& (string)Request.Params["ListBox1Hidden"] == "doubleclicked" )
{
//the Listwas double click Event
}
}
例子如下:
<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>WEB窗体加载时候执行下列代码就能实现双击ListBox中Item执行一些操作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);
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
赞助商链接