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

Group Header Formatting

2 Answers 385 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Timothy Kruszewski
Top achievements
Rank 1
Timothy Kruszewski asked on 18 Oct 2010, 05:00 PM
I have a gridview with 3 layers of grouping and can't figure out how to format the child groups.  For example, I would like to first grouping(Region) to be white, the second grouping(Client) to be black and the third grouping(Team) to be some other color. 

<telerik:RadGrid ID="rg2" runat="server" Skin="Web20" AllowAutomaticUpdates="false"
                                AllowAutomaticDeletes="true" AutoGenerateColumns="false" AllowSorting="true"
                                AllowPaging="false" ShowFooter="true" ShowGroupPanel="false" ShowGroupHeader="true"
                                OnItemDataBound="rg1_ItemDataBound" OnPreRender="rg2_PreRender">
                                <MasterTableView ShowGroupFooter="false" GroupsDefaultExpanded="false" HeaderStyle-BackColor="#7FA5D7"
                                    ItemStyle-BackColor="White" AlternatingItemStyle-BackColor="#B0C4DE" FooterStyle-Font-Bold="true">
                                    <Columns>
                                        <telerik:GridBoundColumn HeaderText="Region" DataField="Region">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Client" DataField="ClientName">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Team" DataField="TeamName" Aggregate="Count">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridTemplateColumn HeaderText="Ticket #" UniqueName="TicketNumber"
                                            DataField="TicketNumber">
                                            <ItemTemplate>
                                                <asp:HyperLink ID="hlTicket" runat="server" Text='<%# Bind("TicketNumber") %>'></asp:HyperLink>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridBoundColumn HeaderText="TicketID" DataField="TicketID" Visible="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="TotalTickets" Visible="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="GridID" Visible="false">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                    <GroupByExpressions>
                                        <telerik:GridGroupByExpression>
                                            <GroupByFields>
                                                <telerik:GridGroupByField FieldName="Region" />
                                            </GroupByFields>
                                            <SelectFields>
                                                <telerik:GridGroupByField FieldName="Region" HeaderText="Region" SortOrder="Ascending" />
                                            </SelectFields>
                                        </telerik:GridGroupByExpression>
                                    </GroupByExpressions>
                                    <GroupByExpressions>
                                        <telerik:GridGroupByExpression>
                                            <GroupByFields>
                                                <telerik:GridGroupByField FieldName="ClientName" />
                                            </GroupByFields>
                                            <SelectFields>
                                                <telerik:GridGroupByField FieldName="ClientName" HeaderText="Client" SortOrder="Ascending" />
                                            </SelectFields>
                                        </telerik:GridGroupByExpression>
                                    </GroupByExpressions>
                                    <GroupByExpressions>
                                        <telerik:GridGroupByExpression>
                                            <GroupByFields>
                                                <telerik:GridGroupByField FieldName="TeamName" />
                                            </GroupByFields>
                                            <SelectFields>
                                                <telerik:GridGroupByField FieldName="TeamName" HeaderText="Team" SortOrder="Ascending" />
                                            </SelectFields>
                                        </telerik:GridGroupByExpression>
                                    </GroupByExpressions>
                                </MasterTableView>
                            </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Oct 2010, 11:30 AM
Hello Timothy,

Check out the following code snippet which shows how to set different backcolor for each level of grouping.

C#:
protected void rg2_PreRender(object sender, EventArgs e)
   {
       foreach (GridGroupHeaderItem headerItem in rg2.MasterTableView.GetItems(GridItemType.GroupHeader))
       {
          string grptext= headerItem.DataCell.Text;
          string[] grpfield = grptext.Split(':');
          if (grpfield[0] == "Region")
              headerItem.DataCell.BackColor = System.Drawing.Color.White;
          else if (gropfield[0] == "Client")
              headerItem.DataCell.BackColor = System.Drawing.Color.Black;
          else if (gropfield[0] == "Team")
              headerItem.DataCell.BackColor = System.Drawing.Color.Blue;
       }
   }

Thanks,
Princy.
0
Timothy Kruszewski
Top achievements
Rank 1
answered on 19 Oct 2010, 04:23 PM
Worked like a charm, the only thing I needed to change was the BackColor to ForeColor because I only wanted the text to display the colors.
Tags
Grid
Asked by
Timothy Kruszewski
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Timothy Kruszewski
Top achievements
Rank 1
Share this question
or