Hi,
If the grid is with AutoGenerateColumns=true then you are in trouble - you
will have to format the DataSource. e.g: If it is a DataTable you will need
to create a new DataTable with the same number of columns all of type
string. Then loop through the rows and columns of the original one and store
the result of ToString(format) on each value in the corresponding cell of
the new DataTable. Then bind the grid with the new datatable.
Otherwise:
For BoundColumn's use the property DataFormatString
For HyperlinkColumn's and ButtonColumn's use the property
DataTextFormatString
For TemplateColumn's - inside the ItemTemplate use the overload of
DataBinder.Eval that takes the format as parameter
e.g:
[C#]
(grid.Columns[0] as BoundColumn).DataFormatString = "{0:#,#.00}";
[VB]
DirectCast(grid.Columns(0), BoundColumn).DataFormatString = "{0:#,#.00}"
Just make sure you set the formats before the call to DataBind() on the
grid.
Greetings
Martin
I've read the article referenced above along with others, but can't get
the
correct coding to format the column in the datagrid. Here's my latest
attempt in trying to format column 3 of the datagrid.
DataGrid1.Columns(3).ToString.Format("#,##0,")
:
Hi,
It is not clear what you need to show, but the following format string:
#,#.00
will produce the following:
51300.01 -> 51,300.01
123123123 -> 123,123,123.00
-3147 -> -3,147.00
If you don't need to show zeros after the decimal point and you know
that
there are at most 5 digits after the decimal point use the following:
#,#.#####
Read more about custom numeric format strings:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomnumericformatstrings.asp
Hope this helps
Martin
I've looked around and have yet to find anything that would answer my
question regarding formating a column in a datagrid. My grid looks
like
this as far as data"
AMHQCON|51300.01|-3147
The first two columns are pretty much text column, but subsequent
columns
1-12 are numerical. I'm trying to get the thousand separator to work.
Any
ideas?