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

Find Specific Hierarchical Grid When Clicking Button in CommandItemTemplate

4 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john81
Top achievements
Rank 1
john81 asked on 17 Mar 2014, 06:34 PM
I have a Hierarchical Grid with a CommandItemTemplate defined in the GridTableView so that each child table has the same Button control that when clicked will reset its filter columns.  What I can't figure out is how to get a reference to the parent GridTableView of the button in the server side button click.

I know how to traverse the ALL the child GridTableViews but I just want to reset the column filters on the GridTableView that the button was clicked in.  To do that I need a reference to the parent GridTableView of the button.  Any ideas how I can get a reference to that?

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Mar 2014, 06:51 AM
Hi,

I guess you want to access the parent table from the detail table on the CommandItemTemplate button click. Please try the following code snippet.

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == "ClearFilters" && e.Item.OwnerTableView.Name == "GridTableViewName")
   {
     GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem);//Accessing the parent row
     string value = parentItem.GetDataKeyValue("ID").ToString(); //Access parent datakey value
     //Your code
   }
}

Thanks,
Princy
0
john81
Top achievements
Rank 1
answered on 18 Mar 2014, 01:11 PM
Not quite what I'm looking for.

If I have say 20 parent records and 20 child GridTableViews, I will have 20 Clear Filter buttions, one for each child GridTableView.

I need to get a reference to the specific GridTableView so I can clear the filters on it using this code below.  I don't want to clear the filters on all the GridTableViews, just the one where the Clear Filter button was clicked.  So the object "gridTableView" in the code below needs to be a reference to the GridTableViews where the button click occurred.

foreach (GridColumn column in gridTableView.Columns)
{
    column.CurrentFilterFunction = GridKnownFunction.NoFilter;
    column.CurrentFilterValue = string.Empty;
}
gridTableView.FilterExpression = string.Empty;
gridTableView.Rebind();


0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Mar 2014, 09:53 AM
Hi,

You can try the following code snippet to clear the current DetailTable filter.

C#:
if (e.CommandName == "ClearFilters" && e.Item.OwnerTableView.Name == "GridTableViewName")
{   
  foreach (GridColumn col in e.Item.OwnerTableView.Columns)
  {
      col.CurrentFilterFunction = GridKnownFunction.NoFilter;
      col.CurrentFilterValue = String.Empty;
  }
  e.Item.OwnerTableView.FilterExpression = String.Empty;
  e.Item.OwnerTableView.Rebind();
}

Thanks,
Princy
0
john81
Top achievements
Rank 1
answered on 19 Mar 2014, 12:18 PM
Perfect.  Thanks!
Tags
Grid
Asked by
john81
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
john81
Top achievements
Rank 1
Share this question
or