Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

asp.net - How to add Double Click mouse event to listbox?

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 !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<%@ 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...