开发者

Display Currency symbols in a Grid

开发者 https://www.devze.com 2023-03-07 23:42 出处:网络
I am retrieving data from sharepoint library in a table. For currency column, i set it as indian currency. And i set spfield.dataformatstri开发者_运维百科ng as {0:c}. It is by default showing $ symbol

I am retrieving data from sharepoint library in a table. For currency column, i set it as indian currency. And i set spfield.dataformatstri开发者_运维百科ng as {0:c}. It is by default showing $ symbol instead of indian currency symbol.

How can i show the actual currency symbol?

Thanks in advance.


You need to pass in the correct culture information to the formatter, however I'm unsure if you can do that directly within the composite formatting, however you could do something like:

string.Format("The total amount is: {0}", total.ToString("c2",
                                          CultureInfo.CreateSpecificCulture("in-IN"));

The other option is to ensure that you've set the culture of your page or site as a whole correctly - clearly the server thinks it's serving pages up by default in the en-US culture.

This can usually be done site wide in the web.config, using the <globalization uiCulture="in" culture="in-IN" /> element, or at the page level in the page directive <%@ Page UICulture="in" Culture="in-IN" %>.

That being said, SharePoint adds some additional complexity into the mix, requiring the site to have been created with the required language, and therefore to have the right language packs installed on top of it.


You need to set the correct culture.


I got the solution. Here is the code snippet:

XmlReader reader = XmlReader.Create(new StringReader(spfield.SchemaXml));
XmlDocument doc = new XmlDocument();
XmlNode node = doc.ReadNode(reader);
string curSymbol = "";
if (node.Attributes["LCID"] != null)
{
    string lcidValue = node.Attributes["LCID"].Value;
    CultureInfo ci = new CultureInfo( Convert.ToInt32(lcidValue));
    curSymbol = ci.NumberFormat.CurrencySymbol;                
}
field.HtmlEncode = false;
field.DataFormatString = curSymbol + " {0:#,###.##}";

It is working fine without do anything in web.config.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号