What's the best way of rounding numbers in an ASP.NET GridView bounded to a DataTable?
I have a GridView that is bound to a DataTable, which in turn uses a TableAdapter, like so:
ResultTableAdapter tableAdapter = new ResultTableAdapter();
ResultDataTable dataTable= tableAdapter.GetResult(id);
gridView.DataSource = dataTable;
This gridview displays many columns with numbers in them. Now I have to display the numbers in thousands with one decimal.
E.g. the number "24753" fr开发者_高级运维om the database should be displayed like "24,8" in the gridview.
What's the cleanest way of accomplishing?
You can use "DataFormatString" property to specify custom number format - check thousands number scaling using ',' in this article. I guess a format string such as "#,##0,.0" should do the trick for you.
I ended up changing the contents of the GridView afterwards, since I found no fast and nice solution to display the numbers in thousands. But it feels wrong.
精彩评论