Showing number in 2 decimal places in GridView

Viewed 108128

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?

7 Answers
<asp:TemplateField HeaderText="Prev Salary" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:Label ID="lblGrdSalary" runat="server" Text='<%#Bind("Salary", "{0:n}") %>'></asp:Label>
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:TemplateField>
Related