网格视图中的数据格式字符串asp.net c# [英] data format string in grid view asp.net c#
本文介绍了网格视图中的数据格式字符串asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在绑定字段中使用数据格式字符串,该字符串会将%附加到我的值上?
示例:
对于卢比,我们可以这样做:
< asp:BoundField DataField ="PassPercent" ItemStyle-Width ="7%" HeaderText ="Pass Percent" DataFormatString ="{0:c}"
我也尝试使用模板字段,但这没用:
< asp:TemplateField HeaderText ="Pass Percent" ItemStyle-Width ="5%">< ItemTemplate>< asp:标签runat ="server" DataValueField ="PassPercent" DataTextField ="PassPercent"/>< asp:Label Text =%" runat ="server"/></ItemTemplate></asp:TemplateField>
解决方案
尝试一下:-
DataFormatString ="{0:p}"
但是,请注意,在这种情况下,百分比以小数形式存储,因此您需要相应地调整值.在 MSDN 上查看格式.
或者您可以简单地对其进行硬编码:-
DataFormatString ="{0}%"
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>
解决方案
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}%"
这篇关于网格视图中的数据格式字符串asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文