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

Grouping

5 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paula
Top achievements
Rank 1
Paula asked on 12 Jul 2010, 11:41 PM
I'm trying to do a simple grouping in my grid but I cannot figure out what I am missing.  All I want in my group "header" i guess it would be called is the field name but for some reason it is coming out [field_title]: [field_name].  When can I remove the field_title and only show field_name?

 

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"

 

 

DataSourceID="sqlCategories" GridLines="None">

 

<

 

MasterTableView DataKeyNames="Main_Category_ID,Sub_Category_ID"

 

 

DataSourceID="sqlCategories">

 

<

 

RowIndicatorColumn>

 

<

 

HeaderStyle Width="20px"></HeaderStyle>

 

</

 

RowIndicatorColumn>

 

<

 

ExpandCollapseColumn>

 

<

 

HeaderStyle Width="20px"></HeaderStyle>

 

</

 

ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="Main_Category"

 

 

SortExpression="Main_Category" UniqueName="Main_Category" Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Sub_Category" HeaderText="Sub_Category"

 

 

SortExpression="Sub_Category" UniqueName="Sub_Category">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Sub_Category_Desc"

 

 

HeaderText="Sub_Category_Desc" SortExpression="Sub_Category_Desc"

 

 

UniqueName="Sub_Category_Desc">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Main_Category_ID" DataType="System.Int32"

 

 

HeaderText="Main_Category_ID" ReadOnly="True" SortExpression="Main_Category_ID"

 

 

UniqueName="Main_Category_ID">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Sub_Category_ID" DataType="System.Int32"

 

 

HeaderText="Sub_Category_ID" ReadOnly="True" SortExpression="Sub_Category_ID"

 

 

UniqueName="Sub_Category_ID">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

<GroupByExpressions>

 

 

<telerik:GridGroupByExpression>

 

 

<SelectFields>

 

 

<telerik:GridGroupByField FieldAlias="Main_Category" FieldName="Main_Category" FormatString="{0}"></telerik:GridGroupByField>

 

 

</SelectFields>

 

 

<GroupByFields>

 

 

<telerik:GridGroupByField FieldName="Main_Category" SortOrder="Descending"></telerik:GridGroupByField>

 

 

</GroupByFields>

 

 

</telerik:GridGroupByExpression>

 

 

</GroupByExpressions>

 

</

 

MasterTableView>

 

 

</telerik:RadGrid>

 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jul 2010, 05:30 AM
Hello Paula,

Try the following code snippet in ItemDataBound event to hide the field title in GroupHeader.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
       if (e.Item is GridGroupHeaderItem)
        {
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item;
            groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
        }
     }

Also refer the following documentation which expalins how to customize GridGroupHeaderItem.
Customizing GridGroupHeaderItem

Thanks,
Princy.

0
Paula
Top achievements
Rank 1
answered on 13 Jul 2010, 03:16 PM
Thanks Princy, that worked!
0
Espen Fosshaug
Top achievements
Rank 1
answered on 16 Sep 2010, 10:53 PM
Hi.

This is working, but I have two levels of grouping and need to change the text in the headers differently.
With this approach each sublevel have the same changed text.

Tried this:
foreach (DataColumn column in groupDataRow.DataView.Table.Columns)
{
    if (column.ColumnName == "MainGroupName")
    {
        item.DataCell.Text = groupDataRow["MainGroupName"].ToString();
    }
    else
    {
        item.DataCell.Text = "Ordrenr.:" + groupDataRow["OrderCopyNo"].ToString() + " VÃ¥r ref.:" + groupDataRow["EmployeeName"].ToString() + "";
    }

But they are still changed the same way. Is there any way I can find which grouping level I am in on databound and then change them differently?
0
Princy
Top achievements
Rank 2
answered on 17 Sep 2010, 05:33 AM
Hello Espen,

Try the following code snippet to set different header text for each level of grouping.

ASPX:
<GroupByExpressions>
    <telerik:GridGroupByExpression>
        <SelectFields>
            <telerik:GridGroupByField FieldName="user_role" HeaderText="user_role" />
        </SelectFields>
        <GroupByFields>
            <telerik:GridGroupByField FieldName="user_role" SortOrder="Descending" />
        </GroupByFields>
    </telerik:GridGroupByExpression>
    <telerik:GridGroupByExpression>
        <SelectFields>
            <telerik:GridGroupByField FieldName="FirstName" HeaderText="FirstName" />
        </SelectFields>
        <GroupByFields>
            <telerik:GridGroupByField FieldName="FirstName" SortOrder="Descending" />
        </GroupByFields>
    </telerik:GridGroupByExpression>
</GroupByExpressions>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridGroupHeaderItem)
      {
          GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item;
          if (groupHeader.DataCell.Text.Split(':')[0] == "user_role")
              groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
          else
              groupHeader.DataCell.Text = groupHeader.DataCell.Text.Split(':')[1];
      }
  }

Thanks,
Princy.
0
Espen Fosshaug
Top achievements
Rank 1
answered on 17 Sep 2010, 09:58 AM
Thanks Princy.

Worked like a charm!

Espen
Tags
Grid
Asked by
Paula
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paula
Top achievements
Rank 1
Espen Fosshaug
Top achievements
Rank 1
Share this question
or