Reputation: 199
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?
Upvotes: 0
Views: 5136
Reputation: 31
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.
Upvotes: 3
Reputation: 108957
Create a BoundField for the currency column with appropriate DataFormatString
.
<asp:BoundField DataField="currencyColumnName" DataFormatString="{0:c}" />
Upvotes: 3