Formatting Columns in an ASP.Net GridView Control

Tue, Jun 23, 2009

Tech Tips

To format columns in a GridView control, you can use the FormatString property:

//Formatting Currency
<asp:GridView id="grid" Runat="Server" >
        <asp:BoundField HeaderText="Amount" DataField="amt" 

To format a Date column, you must also set the HTMLEncode property to “False”.

//Formatting a date column
<asp:BoundField HeaderText="Amount" DataField="date1" 
 FormatString="{0:d}" HTMLEncode="False" />

To format a Currency with no cents:

//No cents in the currency
<asp:BoundField HeaderText="Amount" DataField="amt" 
 FormatString="{0:$#,0}" />
Bookmark and Share

One Response to “Formatting Columns in an ASP.Net GridView Control”

  1. mutuelle Says:

    Merci pour ce post intéressant. si vous continuer ainsi je vais devenir un lecteur fidéle