user1698232
user1698232

Reputation: 183

data format string in grid view asp.net c#

Is there some way I can use a data format string in a bound field which appends % to my value ?

Example :

For rupee we can do this :

  <asp:BoundField DataField="PassPercent" ItemStyle-Width="7%" HeaderText="Pass Percent" DataFormatString="{0:c}"

I tried using a template field too but that didn't work :

<asp:TemplateField HeaderText="Pass Percent" ItemStyle-Width="5%" >
                        <ItemTemplate>
                            <asp:Label runat="server" DataValueField="PassPercent"  DataTextField="PassPercent" />
                            <asp:Label Text="%" runat="server" />
                        </ItemTemplate>
                 </asp:TemplateField>

Upvotes: 0

Views: 5153

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 21795

Try this:-

DataFormatString="{0:p}"

But, please note percentages are stored as decimals in this case so you need to adjust your values accordingly. Check the formatting's here on MSDN.

Or you can simply hard-code it:-

DataFormatString="{0}%"

Upvotes: 1

Related Questions