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
contextmenuevent for the entire gridview:You’d need to change that to individual rows:
Where
rowselectoris however a row is defined in your markup.For instance, if a row is a
<TR>then you would writeOtherwise, if the rows are child
<DIV>elements you might want to write something likeNote that you’re concatenating two plain strings, there’s no javascript variables involved. You might as well write: