开发者

How to format gridview columns?

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?


Create a BoundField for the currency column with appropriate DataFormatString.

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜