Solved

How to force currency symbol on gridview at runtime

Posted on 2010-08-16
6
936 Views
Last Modified: 2012-05-10
Hi experts,

In a gridview that uses...

DataFormatString= "{0:C2}"

...is there any way of forcing the currency symbol?  We run a site that uses the same code-base for a US site and a UK site and I want to leave the global culture as GB but be able to force the currency symbol to $ when the customer is from the US.  How do I do this?

Any help much appreciated as always...

Jay
0
Comment
Question by:jammy-d0dger
  • 3
  • 2
6 Comments
 

Author Comment

by:jammy-d0dger
ID: 33447467
sorry, I meant to say, if I need any code-behind, please supply in VB, not C#.  Many thanks.
0
 
LVL 2

Accepted Solution

by:
MatrixDweller earned 500 total points
ID: 33447640
You would need to override the ItemDataBound of the grid and format the string to include which ever currency symbol you want. In this example I make a hyperlink that hits a javascript function.
Private Sub dgList_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgList.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            Dim sID As String = CType(e.Item.FindControl("lblID"), Label).Text
            CType(e.Item.FindControl("lblID"), Label).Text = "<a href=" & Chr(34) & "javascript:Go(" & sID & ")" & Chr(34) & ">View</a>"
        End If
    End Sub

Open in new window

0
 

Author Comment

by:jammy-d0dger
ID: 33452432
hmm, sorry, this isn't exactly what I had in mind. I appreciate you can build the display at runtime but I was hoping to be able to force the actual currency based on the session.  So, in other words, I guess what I want to do is change the globalisation culture at runtime based on the site that is being viewed.  Is that possible?
0
 
LVL 2

Assisted Solution

by:MatrixDweller
MatrixDweller earned 500 total points
ID: 33454799
You could also prefix the amount with the currency symbol in your SQL query.

You could use the WebUtils.SetUserLocale(currencySymbol) to set the user locale. That's not going to convert your values from US$ to Euro or Pounds etc.

You can get the user's languages by calling this
http://msdn.microsoft.com/en-us/library/system.web.httprequest.userlanguages.aspx
0
 

Author Comment

by:jammy-d0dger
ID: 33617002
Apologies for the delay in returning to this question to close it.  Been one of those projects!  In the end, the solution was very easy, in the page_load event, just set the page.culture to either "en-US" or "en-GB".  It's that simple.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now