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

Setting HeaderText based on property

3 Answers 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahrensberg
Top achievements
Rank 1
Ahrensberg asked on 03 Dec 2009, 12:22 PM
Hi all,

How can I set the HeaderText based on a Property instead of hardcode it?

If I e.g. has property in my cs-file called "EnglishHeader" like this:

public string EnglishHeader 
    get 
    { 
        return "My english header"; 
    } 

And want to get it in the aspx-file something like:

<telerik:GridBoundColumn DataField="OrderNumber" HeaderText="<%= EnglishHeader %>" /> 

Best regards,
Kenneth

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2009, 01:57 PM
Hi,

Databinding expressions are only supported on objects that have a DataBinding event. The  grid columns properties  cannot be set using databinding.Instead  you can use controls like labels inside the HeaderTemplate of a GridTemplateColumn.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn">  
      <HeaderTemplate> 
         <asp:Label ID="lbl" runat="server" Text='<%# EnglishHeader%>'></asp:Label> 
      </HeaderTemplate> 
      <ItemTemplate>    
          ....  
      </ItemTemplate> 
</telerik:GridTemplateColumn> 

Thanks
Princy.
0
Ahrensberg
Top achievements
Rank 1
answered on 07 Dec 2009, 09:29 AM
Thanks for the proposal, but it is unfortunately not the only place i should use this kind of functionality. The idea is that I use a resource-file (.resx) to translate everything in my webapplication, and therefore have to use these text-snippets many places at the site.

Do anyone have an idea what to do? Can I extend radcontrols with for example an attribute called "LanguageResourceID" and depending one what the control are, can do my text-replacing-stuff?
0
Princy
Top achievements
Rank 2
answered on 07 Dec 2009, 09:52 AM
Hello,

Check out the following document which explains on how to localize various elements of Telerik RadGrid using Resource files. Also refer to the code library project link provided within the document.
Localization through resource files

Hope this helps..
Princy.
Tags
Grid
Asked by
Ahrensberg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ahrensberg
Top achievements
Rank 1
Share this question
or