Solved

How to force currency symbol on gridview at runtime

Posted on 2010-08-16
6
945 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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