4

我在 ASP.NET Web 表单中使用 GridView 控件来显示数据记录。我想处理GridView所在行的双击事件。我也应该得到点击了哪一行的信息。

4

5 回答 5

5

请参阅这篇精彩的帖子,它将帮助您解决问题 http://www.codeproject.com/Articles/15677/Clickable-and-Double-Clickable-Rows-with-GridView

于 2012-08-18T13:00:35.740 回答
0

试试我写的这个简单的代码。这个对我有用。

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
于 2018-02-01T03:22:21.503 回答
0
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
于 2018-02-01T03:17:34.060 回答
0

经过多次不成功的尝试,我使用 Jquery 完成了它,这样:

$('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");
    }
});

然后只需在网格按钮命令中设置“wwdblclick”cssClass,如下所示:

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

干杯,

于 2020-01-06T16:35:46.773 回答
-1

您可以尝试使用 RowCommand

http://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.gridview.rowcommand%28v=vs.80%29.aspx

于 2012-08-18T13:01:05.553 回答