Gridview中的货币格式化程序 [英] Currency Formatter in Gridview

查看:54
本文介绍了Gridview中的货币格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,请

我正在建立一个网站,我需要在数据库的边界字段数据上显示正确的货币格式.我想用数字显示的货币是奈及利亚奈拉.我能够通过执行此操作的代码来实现此目的:

Hello please

I''m making a website and i need to display the right currency format on the boundfield data coming from a database.The currency i want to display with the numbers is the Nigeria Naira. I was able to achieved this with code from code behind doing this:

Imports System.Globalization
Dim bz As New CultureInfo("HA-LATN-NG")
str &= Convert.ToDouble(reader.Item("Total Amount")).ToString("c", bz)


进行上述操作可使变量str在尼日利亚奈拉中被格式化.

问题是我该如何处理来自数据库中数据源的gridview上的数据.我尝试将dataformatstring属性设置为{"c",bz),但是它不起作用.
我正在使用的gridview不是通过编程方式创建的.我将其从表设计拖动到网页上.所以请问我如何设置locale属性.假设它是通过编程方式声明的,我本来可以设置数据表的locale属性绑定到gridview.如何使用从表设计器拖到网页上的gridview来执行此操作.请帮助我,这使我无法入睡.
请帮助新手程序员.

在此先谢谢您.


Doing the above makes the variable str to be formatted in the Nigerian Naira.

The problem is how do i do the same with data on a gridview that is coming from a datasource in a database. I have tried setting the dataformatstring property to{"c",bz) but it does not work.
The gridview am using is not created programmatically.I drag it fro the table design unto the web page.so please how can i set the locale property.Assuming it was declared programmatically i would have been able to set the locale property of a datatable before binding to the gridview.How do i do this with a gridview that was dragged from table designer unto a webpage.Please help me out this has been giving me sleepless night.
Please help a novice programmer out.

Thanks in advance.

推荐答案

您需要将区域性设置为数据表.
You need to set the culture to the datatable.
DataTable.Locale Property



因此,在设置数据源之前,先将区域性设置为数据表,然后将数据表分配给gridview.

示例代码



So, before you set the datasource, you set the culture to datatable and then assign the datatable to gridview.

Sample code

DataTable table = new DataTable();
// Create a new CultureInfo
CultureInfo currentCultureInfo = new CultureInfo("en-gb");
table.Locale = currentCultureInfo;



希望这会有所帮助.
欢呼



Hope this helps.
cheers


我使用gridview rowdatabound事件.我做到了,它起作用了
如果e.Row.RowType = DataControlRowType.DataRow然后
e.Row.Cells(3).Text = Double.Parse(e.Row.Cells(3).Text).ToString("C",bz)
I use the gridview rowdatabound event.I did this and it works
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(3).Text = Double.Parse(e.Row.Cells(3).Text).ToString("C", bz)


这篇关于Gridview中的货币格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆