This is a migrated thread and some comments may be shown as answers.

ContextMenu in Hierarchical RadGrid

4 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 2
Steve asked on 31 Oct 2008, 08:25 PM
I have a RadGrid where the MasterTableView has a single DetailTable.  When right-clicking on a row in a DetailTable, a ContextMenu is displayed to perform various operations on the row.

I've successfully grabbed the index of the DetailTable row that was clicked on in the client-side event handler "OnRowContextMenu" and put it in a hidden field, so I can access it in the RadMenu.OnItemClick event handler.  That works just fine; I can grab the value from the hidden field.

What I need to do is get a handle on the GridDataItem associated with the row, and (more importantly) the GridDataItem of the DetailTable row's parent.  How do I do this?  It seems like a pretty common thing someone might need to do when using the ContextMenu with RadGrid.  REALLY need help on this one.  Thanks.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2008, 10:22 AM
Hi,

You can easily get the dataItem of the parent in the context menu item click of the child table:

  protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e) 
    { 
int radGridClickedRowIndex; 
        string UId; 
 
        string[] indices = Request.Form["radGridClickedRowIndex"].Split('_'); 
        radGridClickedRowIndex = Convert.ToInt32(indices[indices.Length - 1]); 
        UId = Request.Form["radGridClickedTableId"]; 
 
        GridTableView tableView; 
 
        switch (e.Item.Text) 
        { 
            case "Select": 
                tableView = this.Page.FindControl(UId) as GridTableView; 
                GridDataItem item = (GridDataItem)tableView.ParentItem; 
                item.BackColor=System.Drawing.Color.Red; 
    } 
 
    } 
 

Thanks,
Princy
0
Steve
Top achievements
Rank 2
answered on 03 Nov 2008, 04:49 PM
How do you get the the ID of the DetailTable in the client-side handler for "OnRowContextMenu"?

0
Princy
Top achievements
Rank 2
answered on 04 Nov 2008, 06:05 AM
Hello Steve,

I assumed that you had retrieved the index of of the DetailTable row. Here is the code to access the DetailTable ID on the client side.
cs:
 <script type="text/javascript"
                function RowContextMenu(sender, eventArgs) 
                { 
                     var menu = $find("<%=RadMenu1.ClientID %>"); 
                     menu.show(eventArgs.get_domEvent()); 
                      
                     document.getElementById("radGridClickedRowIndex").value = eventArgs.get_itemIndexHierarchical(); 
                     var ownerTable = eventArgs.get_tableView(); 
                      
                     document.getElementById("radGridClickedTableId").value = ownerTable._data.UniqueID; 
                } 
                </script> 

Regards,
Princy.
0
Steve
Top achievements
Rank 2
answered on 05 Nov 2008, 03:11 PM
I had retrieved the row but wasn't sure how to get the table ID.  Thanks so much for your help.  I'll give it a try.
Tags
Grid
Asked by
Steve
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Steve
Top achievements
Rank 2
Share this question
or