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

Don't Display Entire Record when Nested Grid Contains Certain Values

3 Answers 5 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 31 Jul 2014, 12:46 AM
I am trying to not display(or remove or hide, etc.) a record when the nested grid for that record contains a certain value. How would I do this in the cs? If it does not contain that value then I would like to display it like it normally would. I have attached a screenshot to better display what I am trying to achieve.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 31 Jul 2014, 07:03 AM
Hi Brett,

You can use the PreRender event of the main grid to hide the row based on its nestedview value. Please try the following code snippet:

C#:
void rgdrMaster_PreRender(object sender, EventArgs e)
{
    foreach (GridDataItem parentItem in rgdrMaster.MasterTableView.Items)
    {
        if (!parentItem .Expanded)
        {
            //accessing the nestedview Radgrid
            GridNestedViewItem nestedItem = (GridNestedViewItem)parentItem.ChildItem;
            RadGrid rgrdChild = (RadGrid)nestedItem.FindControl("rgrdChild");
            foreach (GridDataItem childItem in rgrdChild.Items)
            {
                //Check your condition
                if (childItem["OrderID"].Text == "10643")
                {                
                    parentItem .Display = false;
                }
            }
        }
    }
}

Thanks,
Princy
0
Brett
Top achievements
Rank 1
answered on 31 Jul 2014, 05:24 PM
Thank you for your help. This isn't working for me though. I think it is because I have my rows expanded by default so it is not running the contents within the if. Am I right with this assumption and how would I be able to get the results for my scenario within rows expanded by default?

Thank you,

Brett
0
Princy
Top achievements
Rank 1
answered on 01 Aug 2014, 04:01 AM
HI Brett,

Please modify the code as shown below:

C#:
void rgdrMaster_PreRender(object sender, EventArgs e)
{
  foreach (GridDataItem parentItem in rgdrMaster.MasterTableView.Items)
  {
    GridNestedViewItem nestedItem = (GridNestedViewItem)parentItem.ChildItem;
    RadGrid rgrdChild = (RadGrid)nestedItem.FindControl("rgrdChild");
    foreach (GridDataItem childItem in rgrdChild.Items)
    {
     if (condition)
     {
       parentItem.Display = false;
       nestedItem.Display = false;
     }
    }
  }
}

Thanks,
Princy
Tags
Grid
Asked by
Brett
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Brett
Top achievements
Rank 1
Share this question
or