Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to force currency symbol on gridview at runtime

Posted on 2010-08-16
6
Medium Priority
?
956 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
5 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 2000 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

877 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