Cannot change/set Headertext

4 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 06 Feb 2014 Link to this post

    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.



  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Feb 2014 in reply to Stuart Hemming Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 07 Feb 2014 in reply to Princy Link to this post

    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! :-)
  5. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 11 Feb 2014 Link to this post

    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.
Back to Top