Solved

How to force currency symbol on gridview at runtime

Posted on 2010-08-16
6
932 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now