locked
Column of GridView in RowDataBound in german language RRS feed

  • Question

  • User1872364149 posted

    Hi there, I hope in your help.

    I have problem with set language in c# application connected on a MySQL db.

    The server in use is a Windows Server 2003 in english language.

    I need set the output of query in first column of GridView in RowDataBound in german language.

    If try the same solution in c# application the output is only english.

    This is beginning to make me believe my structure as a whole is not correct.

    What am I missing ?

    I would greatly appreciate any help you can give me in working this problem.

    My code below:

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["Month"]))
                {
                    InitializeCulture();
                    e.Row.Cells[0].Text = string.Format(CultureInfo.CurrentCulture, "{0:MMMM yyyy}", DataBinder.Eval(e.Row.DataItem, "Month"));
                }
            }
        }
    
    
        protected override void InitializeCulture()
        {
            Page.Culture = "de-DE";
            Page.UICulture = "de-DE";
        }

    Friday, September 12, 2014 5:40 AM

Answers

  • User1508394307 posted

    If you only need to output a particular string in a specific format then you don't need to set culture for the page. Just set culture within the String.Format as

    e.Row.Cells[0].Text = string.Format(
             new System.Globalization.CultureInfo("de-DE"), 
             "{0:MMMM yyyy}", DataBinder.Eval(e.Row.DataItem, "Month"));
    

    If you need to set it per page then see example of InitializeCulture() at http://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.90).aspx

    To set culture for entire application you could use web.config 

    <globalization uiCulture="de-DE" culture="de-DE" />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 12, 2014 8:39 AM