简体   繁体   中英

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:

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?

thanks

Right now you're listening to the contextmenu event for the entire gridview:

$("#" + '<%= 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.

For instance, if a row is a <TR> then you would write

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

Otherwise, if the rows are child <DIV> elements you might want to write something like

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

Note that you're concatenating two plain strings, there's no javascript variables involved. You might as well write:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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