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

Dynamic header text - not sortable?

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 30 Jul 2008, 11:16 PM
Hi.  I am successfully setting the header text for a column in the code behind, like so:

protected void RadGrid_Subs_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridHeaderItem)  
            {  
                GridHeaderItem header = (GridHeaderItem)e.Item;  
                header["linklabel"].Text = headerText;  
                  
            }  
        }   

The column code is this (the sortexpression is static):
<telerik:GridTemplateColumn SortExpression="linklabel" UniqueName="linklabel" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" > 
                    <ItemTemplate> 
                        <%# BuildLink(DataBinder.Eval(Container.DataItem, "linkID"), DataBinder.Eval(Container.DataItem, "linkLabel"), DataBinder.Eval(Container.DataItem, "forumID"), DataBinder.Eval(Container.DataItem, "isCase"))%> 
                    </ItemTemplate> 
                </telerik:GridTemplateColumn> 

The column header is not sortable.  If I hardcode the headertext, the sorting works fine.  Am I missing a step?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 31 Jul 2008, 06:56 AM
Hello Angie,

When you set the Text property for a RadGrid header cell the way that you do, you are removing the controls inside this cell, namely - a link button in the default case. This link button is responsible for the sorting functionality.

For easy and painless change of the header cell text, I recommend using one of two techniques described in the following help article:

RadGrid - Localizing the Headers

The first technique uses the ColumnCreated event handler, which is the more correct way to do it. The second technique is similar to yours, but one sets the Text property of the LinkButton inside the cell, not the Text property of the cell itself.


Kind regards,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Angie
Top achievements
Rank 1
answered on 31 Jul 2008, 04:13 PM
The linkbutton example worked for me.  Thank you!
Tags
Grid
Asked by
Angie
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Angie
Top achievements
Rank 1
Share this question
or