I have one GridView in a .aspx page, and am showing dynamic data in this grid, setting AutoGenerateColumns="True"
.
Depending upon which of the options the user selects in a combo box, I am binding different DataTables to the GridView. For example, if the user selects Persons then I am fetching the Persons DataTable, and if the user selects Products then I am fetching Products DataTable.
How can I show a float or double number in 2 decimal places in GridView?
The bound column should have a DataFormatString column. You could do something like:
DataFormatString="{0:0.00}"
Numeric Custom Format Strings
UPDATE
In the case of AutoGenerateColumns="true"
... I'd have to know more specifics about what you're binding, but here are some avenues to explore:
you can write BoundField in GridView:
<asp:BoundField DataField="amount" DataFormatString="{0:n}" />
you can also write TemplateField in GridView
<asp:TemplateField>
<ItemTemplate>
<%#Eval("amount","{0:n}")%>
</ItemTemplate>
</asp:TemplateField>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With