Formatting gridview using rowdatabound event Part 8
>> YOUR LINK HERE: ___ http://youtube.com/watch?v=gl8H7_rjINE
Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists • / kudvenkat • Link for text version of this video • http://csharp-video-tutorials.blogspo... • Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. • / @aarvikitchen5572 • This video is in response to one of my youtube subscriber's question. The subscriber's question is • How can we have multiple cultures for a single page. For example, each row of the grid displays a record for a person belonging to a different country. • When, data is displayed in a gridview control, we want the country specific currency symbol to be displayed, next to their salary. • To achieve this, we can make use of RowDataBound event of GridView control. RowDataBound event is raised when a record in the datasource is bound to a row in gridview control. Please note that in RowDataBound event, we are first checking, if the row, that is being bound, is a datarow. This event is also raised for other row types like Header, Footer etc. • protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) • { • // Check if the row that is being bound, is a datarow • if (e.Row.RowType == DataControlRowType.DataRow) • { • if (e.Row.Cells[3].Text == US ) • { • int salary = Convert.ToInt32(e.Row.Cells[2].Text); • string formattedString = string.Format(new System.Globalization.CultureInfo( en-US ), {0:c} , salary); • e.Row.Cells[2].Text = formattedString; • } • else if (e.Row.Cells[3].Text == UK ) • { • int salary = Convert.ToInt32(e.Row.Cells[2].Text); • string formattedString = string.Format(new System.Globalization.CultureInfo( en-GB ), {0:c} , salary); • e.Row.Cells[2].Text = formattedString; • } • else if (e.Row.Cells[3].Text == India ) • { • int salary = Convert.ToInt32(e.Row.Cells[2].Text); • string formattedString = string.Format(new System.Globalization.CultureInfo( en-IN ), {0:c} , salary); • e.Row.Cells[2].Text = formattedString; • } • else if (e.Row.Cells[3].Text == South Africa ) • { • int salary = Convert.ToInt32(e.Row.Cells[2].Text); • string formattedString = string.Format(new System.Globalization.CultureInfo( en-ZA ), {0:c} , salary); • e.Row.Cells[2].Text = formattedString; • } • else if (e.Row.Cells[3].Text == Malaysia ) • { • int salary = Convert.ToInt32(e.Row.Cells[2].Text); • string formattedString = string.Format(new System.Globalization.CultureInfo( en-MY ), {0:c} , salary); • e.Row.Cells[2].Text = formattedString; • } • } • } • Use the code below, to get the list of all supported cultures in asp.net • foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures)) • { • Response.Write(ci.Name + - + ci.DisplayName + | ); • }
#############################
