Sometimes you may want to format data type in repeater. Here are some examples of formatting data in repeater-
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="dsData">
<HeaderTemplate>
<table cellpadding="2" cellspacing="2" style="border: 1px solid gray; font-size: 10px;">
<tr style="background-color: #A5BFDD; border: 1px solid gray">
<th>
Year
</th>
<th>
Visits
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="border: 1px solid gray">
<td>
<%# Eval("Year") %>
</td>
<td>
<%# DataBinder.Eval( Container,"DataItem.tot_visits", "{0:N0}") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
The output for this is – 276,773.00 .
Now if you want to no decimal point in the number formatting, just try –
<%# DataBinder.Eval( Container,"DataItem.tot_visits", "{0:N0}") %>
This will display result like – 276,773. Basically when I placed 0 after N it format the data into no decimal.
Here are some other formatting options –
Cn¦cn String.Format("{0:C}", 1234.56) $1,234.56
String.Format("{0:C3}", 1234.56789) $1,234.568
String.Format("{0:C}", -1234.5) ($1,234.50)
Dn¦dn String.Format("{0:D}", 1234) 1234
String.Format("{0:D6}", 1234) 001234
String.Format("{0:D}", 11234) -1234
Fn¦fn String.Format("{0:F}", 1234.56) 1234.56
String.Format("{0:F4}", 1234.56) 1234.5600
String.Format("{0:F1}", -1234.567) -1234.6
Nn¦nn String.Format("{0:N}", 1234.56) 1,234.56
String.Format("{0:N4}", 1234.56) 1,234.5600
String.Format("{0:N1}", -1234.567) -1,234.6
Pn¦pn String.Format("{0:P}", .1234) 12.34 %
String.Format("{0:P0}", .1234) 12 %
String.Format("{0:P1}", -.1234) -12.3 %
