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

DetailItemTemplate not collapsing

4 Answers 148 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Todd A
Top achievements
Rank 1
Todd A asked on 22 Jan 2014, 09:23 PM

I have a grid with a DetailItemTemplate defined.  

On the PreRender method of the grid, I get all the GridGroupHeaderItems and I set the Expanded property to false.  

The grid displays correctly except the DetailItemTemplate rows are visible.

When I open it using the control, it shows the rows and associated detail rows, and when I collapse it on the page it works correctly -- just not from the PreRender method.

Is there something else that I need to set or a workaround?

Thanks,
Todd.


4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jan 2014, 09:34 AM
Hi Todd

I'm not sure about your scenario, i was not able to replicate the issue. If you want the Groups default Expanded state to be false, you can set in aspx as follows, the DetaiItemTemplate was hidden in all my cases:

ASPX:
<MasterTableView  GroupsDefaultExpanded="false" >

OR in the code behind you can use:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridGroupHeaderItem)
  {
   GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
   item.Expanded = false;
  }
}

Please provide your code snippet if this doesn't help.
Thanks,
Princy
0
Todd A
Top achievements
Rank 1
answered on 23 Jan 2014, 04:54 PM

The solution was to set the Expanded property in the ItemDataBound method versus the PreRender method for the grid.

Both work fine without a DetailItemTemplate, but with a DetailItemTemplate using the PreRender method, the DetailItemTemplate is still shown.  I've included images attached and the different code below.

protected void TestGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
     
    if (e.Item is GridGroupHeaderItem)
    {
        GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
        item.Expanded = false;
    }
      
}
 
protected void TestGrid_PreRender(object sender, EventArgs e)
{
    /*
    ArrayList groupItems = new ArrayList(TestGrid.MasterTableView.GetItems(GridItemType.GroupHeader));
 
    foreach (GridGroupHeaderItem item in groupItems)
    {
        item.Expanded = false;
    }
     * */
     
}

<telerik:RadGrid ID="TestGrid" runat="server" EnableViewState="True" AutoGenerateColumns="False" Width="500" ShowFooter="false"
                 OnItemDataBound="TestGrid_ItemDataBound" OnPreRender="TestGrid_PreRender" EnableLinqExpressions="false" >
    <MasterTableView GroupLoadMode="Client">
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="WeekNumber" HeaderText="Week" HeaderValueSeparator=": " />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="WeekNumber" SortOrder="Ascending" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <Columns>
            <telerik:GridBoundColumn DataField="Id" HeaderText="Value" />
 
        </Columns>
        <DetailItemTemplate>
            <asp:TextBox ID="CommentsTextBox" runat="server" TextMode="MultiLine" Width="600" Rows="2" MaxLength="200" Font-Size="10" OnFocus="this.select();" />
        </DetailItemTemplate>
    </MasterTableView>
    <ClientSettings EnableRowHoverStyle="false" AllowExpandCollapse="true">
        <Selecting AllowRowSelect="false" EnableDragToSelectRows="false" />
    </ClientSettings>
</telerik:RadGrid>


0
Shinu
Top achievements
Rank 2
answered on 24 Jan 2014, 03:28 AM
.
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2014, 03:36 AM
Hi Todd,

In your case you can use the ItemDataBound event. Indeed, the DataItem property is available only during data binding. You can access/use it in the ItemDataBound event if it works for you. On RadGrid PreRender, you can get only the text of the GridGroupHeader.

Thanks,
Princy
Tags
Grid
Asked by
Todd A
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Todd A
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or