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

[Solved] Grouping - GridTemplateColumn

2 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
azin ramezani
Top achievements
Rank 1
azin ramezani asked on 31 Aug 2009, 09:02 AM

I have a GridTemplateColumn like this:

<telerik:GridTemplateColumn UniqueName="PrsSex" GroupByExpression="PrsSex Group By PrsSex">  
    <HeaderTemplate> 
      <asp:Label runat="server">PrsSex</asp:Label> 
    </HeaderTemplate> 
    <ItemTemplate> 
      <asp:Label   
Text='<% #Eval("PrsSex").ToString()== "0" ? "Female" : "Male" %>' runat="server" />                                            </ItemTemplate>                                          
</telerik:GridTemplateColumn> 
 

I want to change its name in groupPanel from "PrsSex" to "Sex". In GridGroupsChangingEventHandler I am trying to change its HeaderText like below, but it does not work!

private void grdPrs_GroupsChanging(object source, GridGroupsChangingEventArgs e)  
    {  
        //Expression is added (by drag/grop on group panel)  
        if (e.Action == GridGroupsChangingAction.Group)  
        {  
            if (e.Expression.GroupByFields[0].FieldName == "PrsSex")  
            {  
                e.Expression.GroupByFields[0].HeaderText = "Sex";  
            }  
     }  
}  
 
Thanks.

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 03 Sep 2009, 07:15 AM
Hello azin,

You should use  group expression's SelectFields instead of GroupByFields. Similar to the following:

protected void grdPrs_GroupsChanging(object source, GridGroupsChangingEventArgs e)  
    {  
        //Expression is added (by drag/grop on group panel)     
        if (e.Action == GridGroupsChangingAction.Group)  
        {  
            if (e.Expression.GroupByFields[0].FieldName == "PrsSex")  
            {  
                e.Expression.SelectFields[0].HeaderText = "Sex";  
            }  
        }  
    } 


Greetings,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
azin ramezani
Top achievements
Rank 1
answered on 03 Sep 2009, 07:45 AM
Thanks Rosen!
also, I want to modify the HeaderValue. Now it shows 0 and 1 infront of HeaderText, I want to change it for example to Male or Female. How can I handle that?
Tags
Grid
Asked by
azin ramezani
Top achievements
Rank 1
Answers by
Rosen
Telerik team
azin ramezani
Top achievements
Rank 1
Share this question
or