Solved

How to force currency symbol on gridview at runtime

Posted on 2010-08-16
6
941 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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