Client side code:
<script type="text/javascript">
function RowContextMenu(sender, e)
{
var index = e.get_itemIndexHierarchical();
document.getElementById("radGridClickedRowIndex").value = index;
var menu = $find("<%= PractitionerContextMenu.ClientID %>");
var evt = e.get_domEvent();
menu.show(evt);
e.cancelBubble = true;
e.returnValue = false;
if (e.stopPropagation)
{
e.stopPropagation();
e.preventDefault();
}
sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
}
</script>
Add the following into your RadGrid
<ClientSettings>
<ClientEvents OnRowContextMenu="RowContextMenu"></ClientEvents>
<Selecting AllowRowSelect="true" />
</ClientSettings>
Also make sure you have the DataKeyNames property set on the RadGrid:
DataKeyNames="Id"
Then in the code-behind have this method for the OnItemClick property of the RadContextMenu
protected void ContextMenu_ItemClick(object sender, RadMenuEventArgs e)
{
int gridClickedRowIndex = Convert.ToInt32(Request.Form["radGridClickedRowIndex"], CultureInfo.CurrentCulture);
int id = (int)PractitionerGrid.Items[gridClickedRowIndex].GetDataKeyValue("Id");
// Do whatever
}
Subscribe to:
Post Comments (Atom)
1 comment:
very helpful, thanks! Been trying for a couple of hours to get client side row id from a context menu.
Post a Comment