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

[Solved] Grid header text -- Losing sort

1 Answer 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Lindsay
Top achievements
Rank 1
Adam Lindsay asked on 09 Dec 2009, 04:45 AM
I am using the following code to change the header on a grid:

protected

 

void RouteInquiryGrid_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

if ((e.Item is GridHeaderItem))

 

{

 

GridHeaderItem header = (GridHeaderItem)e.Item;

 

 

if (SessionHelper.Instance.WeightUOM.Id == WeightUOM.English.Id)

 

{

header[

"ContainerWeightQty"].Text = "Weight" + WeightUOM.GetAsString(WeightUOM.English.Id);

 

}

 

else

 

{

header[

"ContainerWeightQty"].Text = "Weight" + WeightUOM.GetAsString(WeightUOM.Metric.Id);

 

}

}

}

This works great and the header text is changed.  However, when I do this I lose the ability to sort on the column.  Is there an easy way to get the sort active again.

Thanks,

- Adam

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Dec 2009, 05:58 AM
Hi Adam,

Try setting the Text property of HeaderItem LinkButton as shown in the example.

CS:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
            LinkButton literalControl = (LinkButton)headerItem["CompanyName"].Controls[0]; 
            literalControl.Text = "Custom text"
        } 
    } 

-Shinu.
Tags
Grid
Asked by
Adam Lindsay
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or