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

Cannot change/set Headertext

3 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 06 Feb 2014, 04:45 PM
OK. Here's the deal.

I have a Grid that is defined with columns like this ...
1.<telerik:GridTemplateColumn UniqueName="DateTimeAdded" SortExpression="DateTimeAdded">
2.    <ItemTemplate>
3.        <div id="lblDateTime2"/>
4.    </ItemTemplate>
  5..
</telerik:GridTemplateColumn>

And I have some code behind that looks like this ...
1.switch (item.UniqueName)
2.                {
3.                    case "DateTimeAdded":
4.                        item.HeaderText = GetGlobalStringResource(GTypes.Task.TASK_LIST, GKeys.Task.TaskList.GRID_COLUMN_HEADER_TEXT_DATE_TIME);

Now, I've tried invoking this code in the OnLoad event and in both the Page and the Grid's OnPreRender event. In each case I can see the value of item.headerText being correctly set. However, it is NEVER rendered.

I can't call this during the ItemDataBound event as the grid is bound on the client.

I can't call this during the OnColumnCreated/OnConlumnCreating events as they aren't invoked.

I'd welcome any suggestions.



3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Feb 2014, 06:58 AM
Hi Stuart Hemming,

Please try the following code snippet to set HeaderText property of the Grid Columns:

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
 {
  switch (col.UniqueName)
  {
   case "DateTimeAdded": col.HeaderText = "Header Text";
                   break;              
  }          
 }
 RadGrid1.Rebind();
}

Thanks,
Princy
0
Stuart Hemming
Top achievements
Rank 2
answered on 07 Feb 2014, 08:00 AM
Whilst that does update the headers, it's of no use. As I said in my original message, the grid is bound on the client. Consequently, I end up with a grid that has the right headers but nothing else! :-)
0
Konstantin Dikov
Telerik team
answered on 11 Feb 2014, 12:53 PM
Hi Stuart,

If I understand correctly, the remaining issue is that there is no data within your columns, which from the provided code snippet is rather expected, since there is no DataField property set in your column, neither any binding expression are present.

Please have a look at the following online demos and help articles that could prove helpful for your requirements:

Hope that helps.


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Stuart Hemming
Top achievements
Rank 2
Konstantin Dikov
Telerik team
Share this question
or