0

Can I use double-click on a asp.net listview? I want to call a function on double-click rather than single i.e ItemCommand.

Is it at all possible?

Ta!

ninety
  • 19
  • 6

2 Answers2

0

If calling function is referring to server side call simple thing would be

private void listView_MouseDoubleClick(object sender, MouseEventArgs e)
{
  MessageBox.Show("Double Click Event Called");
}

For more info on same check:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doubleclick.aspx

And if calling function refers to any client side (Javascript/Jquery call) then you can use:

 $('#target').dblclick(function() {
  alert('Handler for .dblclick() called.');
 })

for more info check here

Pratik
  • 1,472
  • 7
  • 20
  • 36
0

ASPX:

<asp:ListView ID="ListView1" runat="server" 
    onitemdatabound="ListView1_ItemDataBound" onitemcommand="ListView1_ItemCommand">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" CommandName="DoubleClick" runat="server">LinkButton</asp:LinkButton>
    </ItemTemplate>
</asp:ListView>

CS:

protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            LinkButton LinkButton1 = (LinkButton)e.Item.FindControl("LinkButton1");
            string _jsDouble = ClientScript.GetPostBackClientHyperlink(LinkButton1, "");
            LinkButton1.Attributes["ondblclick"] = _jsDouble;
            LinkButton1.Attributes["onclick"] = "return false;";    
        }
    }

    protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "DoubleClick")
        {

        }
    }
ahaliav fox
  • 2,217
  • 22
  • 21
  • This does the trick. Each element of the listview is surrounded by asp:LinkButton so I can click any piece of info.; rather than loop each LinkButton0-15 & add the attirbutes can anyone suggest a bit of jquery to do the whole lot? – ninety Dec 17 '12 at 14:12