How to format gridview columns?

百般思念 提交于 2019-12-02 15:13:31

问题


Below is my code:

var grid = new GridView();
grid.DataSource = myDataset;

grid.DataBind();

I want to format some of the columns of my grid to Currency with thousand separator and with decimal like '$9,999,999.99'.

I am exporting the grid to excel and I want to see the values in currency format.

I am creating gridview during runtime. I have no html code for my gridview.

I am just bounding dataset to gridview and exporting to excel. I won't see gridview in HTML format.

How to do that?


回答1:


Create a BoundField for the currency column with appropriate DataFormatString.

<asp:BoundField  DataField="currencyColumnName" DataFormatString="{0:c}" />



回答2:


Google brought me here, so I thought I'd share my answer. Here's how I got to format one cell to currency in asp.net.

With Me.ratesGridView
        .Rows(i).Cells(4).Text = FormatCurrency(.Rows(i).Cells(4).Text)
End With

Enjoy.



来源:https://stackoverflow.com/questions/6206338/how-to-format-gridview-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!