Best practice for show localized display name for MetaTable and MetaColumn RRS feed

  • Question

  • User-323784514 posted

    Hi, I'm setting the DisplayName in database model's Metatable, and it can be shown in my ASP.NET DYNAMIC DATA website, like this:

    public class ItemModel
        public Guid Id { get; set; }
    class ItemMetadata
        [Display(Order = 1)]
        public Guid Id;
        [Display(Name = "ThisIsItemName", Order = 3)]
        public string ItemName;

    it's good, the website can reflect and show the string I've put in, but now my website need to support different locale languages, so I created a customized Attribute to allow pass in a RESOURCE string key, 

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field, AllowMultiple = false)]
    public class LocalizeDisplayName : Attribute
        public LocalizeDisplayName(string localizedStringKey)
            this.StringKey = localizedStringKey;
        public string StringKey { get; }

    use it like this:

    class ItemMetadata
        [Display(Order = 1)]
        public Guid Id;
        [LocalizeDisplayName(Name = "DynamicDataWebSite_Model_Item_Column_ItemName", Order = 3)]
        public string ItemName;

    and then in website pages code which for showing this model, I can resolve the localized string key from a RESOURCE file, then get the localized string:

    var target = metaTable.Attributes[typeof(LocalizeDisplayName)];
    var localizedStr = Resources.Strings.ResourceManager.GetString(((LocalizeDisplayName)target).StringKey, CultureInfo.CurrentCulture);

     above code is easy to inject to most code in aspx.cs, but for those GridView and etc., most of its binding logical are behind the scence, like this is a sample code from Visual Studio Dynamic data website template for showing a list of values for a model:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
            AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
            RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
                        <asp:LinkButton runat="server" CommandName="Edit" Text="Edit" OnClientClick='return confirm("Super admin, Are you sure you want to edit this item?");' />&nbsp;
                        <asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
                                    OnClientClick='return confirm("Super admin, Are you sure you want to delete this item?");' />&nbsp;
                        <asp:DynamicHyperLink runat="server" Text="Details" />
            <PagerStyle CssClass="DDFooter" />
                <asp:GridViewPager runat="server" />
                There are currently no items in this table.

    for here, I want the header row showing the localized string which marked in Metatable's MetaColumn, like the column `ItemName` which marked with RESOURCE KEY


     so How I can achieve this by a generic way that suits all types of models?

    Sunday, August 27, 2017 9:48 AM

All replies

  • User-330204900 posted

    I would extend the MetaTable and MeltaColumn classes and then use those in my application 


    public class LocalizedMetaModel : MetaModel


    public class LocalizedSecureMetaTable : MetaTable


    public class LocalizedSecureMetaColumn : MetaColumn


    then override the DisplayName property get the LocalizeDisplayNameAttribute if it exists and return that localised name.

    This is a simplistic approach and does not take into account the clients local, which you may need to acquire from  the client and pass to the Table/Column via a function during the Session staturup.

    Sunday, August 27, 2017 12:55 PM
  • User-335504541 posted

    Hi shawn.shao,

    Since you could get the localized string in behind code, you could also set the header in behind code.

    For example:

     GridView1.HeaderRow.Cells[0].Text = localizedStr;

    Best Regards,


    Monday, August 28, 2017 9:45 AM