Monday, March 26, 2012

Show Value upto Two Decimal Places in Gridview

Show money or float values upto two decimal places using 
String.Format in Gridview.
 
<%# String.Format("{0:f2}",DataBinder.Eval(Container.DataItem,"Rate")) %>
 or
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Amt","{0:f2}")  %>'></asp:Label> 
 
Example :  
<asp:TemplateField  HeaderText="Rate">
<ItemTemplate>
   <table align="right" style="text-align: right"><tr><td align="right">
    <asp:Label ID="lblRate" runat="server" 

Text='<%# String.Format("{0:f2}",DataBinder.Eval(Container.DataItem,"Rate")) %>' ></asp:Label>
   </td></tr></table>
</ItemTemplate>
</asp:TemplateField>

5 comments:

  1. Worked like a charm :) thanks a lot !!

    ReplyDelete
  2. I have used the same but it is not working

    ReplyDelete
  3. I am used data table decimal sum calculation but currency format used string type convert to bind gridview so controvert method solution tell me

    ReplyDelete