Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello please

I'm making a website and i need to display the right currency format on the boundfield data coming from a database.The currency i want to display with the numbers is the Nigeria Naira. I was able to achieved this with code from code behind doing this:
VB
Imports System.Globalization
Dim bz As New CultureInfo("HA-LATN-NG")
str &= Convert.ToDouble(reader.Item("Total Amount")).ToString("c", bz)

Doing the above makes the variable str to be formatted in the Nigerian Naira.

The problem is how do i do the same with data on a gridview that is coming from a datasource in a database. I have tried setting the dataformatstring property to{"c",bz) but it does not work.
The gridview am using is not created programmatically.I drag it fro the table design unto the web page.so please how can i set the locale property.Assuming it was declared programmatically i would have been able to set the locale property of a datatable before binding to the gridview.How do i do this with a gridview that was dragged from table designer unto a webpage.Please help me out this has been giving me sleepless night.
Please help a novice programmer out.

Thanks in advance.
Posted
Updated 25-Aug-12 8:19am
v6
Comments
ZurdoDev 23-Aug-12 9:44am    
If you set the DataFormatString to C it should work but you also have to set the culture on every postback, not just once.
Kenneth Haugland 23-Aug-12 10:05am    
Is this WinForms, WPF ASP.NET or or or?
jamiebones 23-Aug-12 13:11pm    
It is an asp website application
Kenneth Haugland 23-Aug-12 15:46pm    
Are you binding the values to the datatable, if so you could always use a converter in the binding

You need to set the culture to the datatable.
DataTable.Locale Property


So, before you set the datasource, you set the culture to datatable and then assign the datatable to gridview.

Sample code
DataTable table = new DataTable();
// Create a new CultureInfo
CultureInfo currentCultureInfo = new CultureInfo("en-gb");
table.Locale = currentCultureInfo;


Hope this helps.
cheers
 
Share this answer
 
I use the gridview rowdatabound event.I did this and it works
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(3).Text = Double.Parse(e.Row.Cells(3).Text).ToString("C", bz)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900