简体   繁体   English

如何在gridView中显示某行的上下文菜单

[英]How to Show Context Menu for some row in gridView

I have a gridview that it bind to a data table.I want to add context ment for rows that has a condition. 我有一个绑定到数据表的网格视图。我想为有条件的行添加上下文。 I use this code in RowDataBound event: 我在RowDataBound事件中使用以下代码:

if (e.Row.Enabled == true && e.Row.Cells[6].Enabled == true)
        {
            e.Row.CssClass = "HasMenu";
        }

now I write this code to show context menu on grid: 现在,我编写以下代码以在网格上显示上下文菜单:

$(document).ready(function () {

        $('#menu').click(function () {
            $('#menu').hide();
        });
        $(document).click(function () {
            $('#menu').hide();
        });


        $("#" + '<%= GridView1.ClientID %>').bind("contextmenu", function (e) {
            $('#menu').css({
                top: e.pageY + 'px',
                left: e.pageX + 'px'
            }).show();

            return false;

        });
    });

the problem is I don't show any context menu(not explorer context menu and not my custom context menu) on the rows that has no HasMenu css class and show Context menu for rows that has HasMenu css class .what change need on my script? 问题是我不显示任何上下文菜单上没有的行(不是资源管理器右键菜单,而不是我的自定义上下文菜单) HasMenu的行CSS类,并显示上下文菜单有HasMenu CSS类。什么在我的脚本需要改变?

thanks 谢谢

Right now you're listening to the contextmenu event for the entire gridview: 现在,您正在收听整个gridview的contextmenu事件:

$("#" + '<%= GridView1.ClientID %>')

You'd need to change that to individual rows: 您需要将其更改为单独的行:

$('#" + '<%= GridView1.ClientID %> rowselector.HasMenu')

Where rowselector is however a row is defined in your markup. 但是,在rowselector所在的地方,标记中定义了一行。

For instance, if a row is a <TR> then you would write 例如,如果某行是<TR>则您将编写

$("#" + '<%= GridView1.ClientID %> tr.HasMenu')

Otherwise, if the rows are child <DIV> elements you might want to write something like 否则,如果行是子<DIV>元素,则可能需要编写如下内容

$("#" + '<%= GridView1.ClientID %> > div.HasMenu')

Note that you're concatenating two plain strings, there's no javascript variables involved. 请注意,您要串联两个纯字符串,不涉及任何javascript变量。 You might as well write: 您最好写:

$('#<%= GridView1.ClientID %> rowselector.HasMenu')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM