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

How to show hide rows of a template conditionally

1 Answer 533 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erion
Top achievements
Rank 1
Erion asked on 26 Aug 2011, 01:30 AM
Hi, 

I have information displayed on the grid, which has a template to be displaying additional information. 
The additional information may not be applicable based on the dates of the parent row. 

I have tried to hide the rows, on the on the CreateRow event. The problem here, is then when I expend a parent row, once the child row get's hidden once, it does not get examined for creation if I expand another parent row. 

So for example :

1. Parent collection is a list of strings < "two" , "one" > . Child collection is < " 1, " 2", " 3">. 
2. Let's say that I have bound the parent and the child collection using the Template Paradime, on some column with the name "ID", which both template and grid have and it is being populated. 

3. Now if the user expands the row containing " two" I want to show only child collection < " 1", "2" > . If the user clicks on the row  containing " one ", I want the sub grid to show < "1","3" > 

I have tried to set the child rows as visible based on some condition on the CreateRow event, but the rows that were marked as hidden, don't get considered if the user clicks on another parent row.  In our example the child row with value "1", once is marked as hidden (  e.RowInfo.IsVisible = false; ) , it remains hidden and it never get's considered when the user clicks on the row with string " one ". 

Is there a way to do this, in the grid ? 

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 29 Aug 2011, 02:35 PM
Hello Erion,

Thank you for writing.

I am not sure if CreateRow event is appropriate in the described scenario. It is thrown while grid creates a row element. That element can be reused afterwards, because of the grid virtualization. Instead, I would suggest that you use the IsVisible property of the RowInfo object. You can iterate through child rows and set IsVisible according to your custom requirement. As an example, ChildViewExpanded event can be used:
void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e)
{
    object controlValue = e.ParentRow.Cells["Region"].Value;
    if (controlValue == null || String.IsNullOrEmpty(controlValue.ToString()))
    {
        foreach (var row in e.ParentRow.ChildRows)
        {
            if (row.Cells["ShipVia"].Value != null
                && (int)row.Cells["ShipVia"].Value != 1)
            {
                row.IsVisible = false;
            }
        }
    }
}

Hope this helps. Let me know if you have any additional questions.

Greetings,
Martin Vasilev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Erion
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or