Sunset at Oak Island, North Carolina

Spider Web Woman Designs

Formatting number fields in an ASP.NET GridView

Format a field as Currency

Common GridView Tasks > Edit Columns

Select the fields from the Selected fields list

Under BoundField > Behavior properties, set HtmlEncode to False

Under BoundField > Data Properties, setDataFormatString to {0:C2}

(The C means Currency, the 2 represents the number of positions after the decimal point.)

And click OK

This is what the code looks like:

<asp:boundfield HtmlEncode="False" DataFormatString="{0:C2}" DataField="salary" SortExpression="salary" HeaderText="salary"> </asp:boundfield>

Format a field as a Percent

The field in the Access database was defined as: Field Size: Single, Format: Percent, and Decimals Places: Auto.

Common GridView Tasks > Edit Columns

Select the fields from the Selected fields list

Under BoundField > Behavior properties, set HtmlEncode to False

Under BoundField > Data Properties, setDataFormatString to {0:P2}

(The P means Percent, the 2 represents the number of positions after the decimal point.)

And click OK

This is what the code looks like:

<asp:boundfield HtmlEncode="False" DataFormatString="{0:P2}" DataField="amount" SortExpression="amount" HeaderText="amount"> </asp:boundfield>


Back to Working with Access Databases in Microsoft Expression Web

 



Email UsWe're on Google+LinkedIn ProfileFollow us on TwitterLike Us on Facebook!