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

how to create dynamic context menu in hierarchy grid

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vikas gupta
Top achievements
Rank 1
vikas gupta asked on 24 May 2012, 10:40 AM
how can i creae context menu  in hierarchy grid.

To add,delete and update the item for each grid from code behind.


Thanks Telerik Team

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 May 2012, 12:15 PM
Hello Vikas,

You can add the ContextMenu to add, delete and update operation using the following code.
C#:
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 "Delete":
     tableView = this.Page.FindControl(UId) as GridTableView;
    RadGrid2.MasterTableView.PerformDelete(RadGrid2.Items[radGridClickedRowIndex]);
     (tableView as GridTableView).PerformDelete(RadGrid2.Items[radGridClickedRowIndex]);
   break;
  case "Edit":
  tableView = this.Page.FindControl(UId) as GridTableView;
  ((tableView as GridTableView as GridTableView).Items[radGridClickedRowIndex] as GridDataItem).Edit = true;
  tableView.Rebind();
   break;
   case "Add":
   tableView = this.Page.FindControl(UId) as GridTableView;
   (RadGrid2.MasterTableView.Items[index] as GridDataItem).ChildItem.NestedTableViews[0].IsItemInserted = true;
   tableView.Rebind();
   break;
  }
}
protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
//codefor updating the grid
}
 protected void RadGrid2_InsertCommand(object sender, GridCommandEventArgs e)
    {
//codefor inserting
    }

Thanks,
Shinu.
Tags
Grid
Asked by
vikas gupta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or