4
votes

I am using a GridView control in ASP.NET web form to display the data records. I want to handle the double click event of the row of the GridView. also I should get information which row is clicked.

5
do you want to do this via javascript? beacuse there is no server side event for it. - Kundan Singh Chouhan
I would like any way without changing view of my gridview or website - Rohit Chaudhari

5 Answers

5
votes
0
votes
Protected Sub GridView2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

    Dim row As GridViewRow = GridView1.SelectedRow

    Dim i As Integer = 0
    GridView1.Rows(row.RowIndex).BackColor = ColorTranslator.FromHtml("#A1DCF2")
    MsgBox(doubleClick & " " & GridView1.SelectedIndex.ToString)
    If doubleClick = GridView1.SelectedIndex.ToString Then
        MsgBox("Yo")
    End If
    doubleClick = GridView1.SelectedIndex.ToString
End Sub
0
votes

Try this simple code I wrote. It works for me.

Protected Sub GridView2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
    Dim row As GridViewRow = GridView1.SelectedRow
    Dim i As Integer = 0
    GridView1.Rows(row.RowIndex).BackColor = ColorTranslator.FromHtml("#A1DCF2")
    MsgBox(doubleClick & " " & GridView1.SelectedIndex.ToString)
    If doubleClick = GridView1.SelectedIndex.ToString Then
        MsgBox("Yo")
    End If
    doubleClick = GridView1.SelectedIndex.ToString
End Sub
0
votes

After a lot of unsuccessful tries, I got it done using Jquery, this way:

$('html').on('click', ".wwdblclick", function (e) {
    e.preventDefault;
    return false;
});

$('html').on('dblclick', ".wwdblclick", function (e) {
    var x = $(this).attr("href").replace("javascript:", "");
    $(this).attr("ondblclick", x);
    if (!(typeof $(this).attr("wwRunningDblclick") !== "undefined")) {
        $(this).attr("wwRunningDblclick", "true");
        $(this).trigger("dblclick");
    }
    else {
        $(this).removeAttr("wwRunningDblclick");
    }
});

Then just set the "wwdblclick" cssClass in your grid button command, like this:

<asp:LinkButton ID="lkbX" runat="server" Text="<i class=icon-minus-sign></i>" CssClass="wwdblclick" CommandName="action" CommandArgument='<%# Eval("id") %>' />

Cheers,