在GridView控件格式十进制值 [英] format decimal value in gridview
问题描述
我在我的GridView这是越来越从数据库表其值绑定的字段。
I have a bound field in my Gridview which is getting its value from a database table.
我有数据,但不知道如何对其进行格式化在GridView里面。
I have got the data but don't know how to format it inside the gridview.
例如我得到的总的数据从下面像123456,但我想显示为123456
For example I get total data from below like "123456", but I want to display as "123,456"
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
ReadOnly="True" SortExpression="totaldata" />
我怎样才能做到这一点?我需要绑定字段转换为模板字段?但是,这样做之后,我做
How can I do this? Do I need to convert the bound field into a template field ? But what do i do after that.
请帮忙
我已经使用DataFormatString ={0。: 。N0},它解决了上述问题。
I have used DataFormatString="{0:n0}" and it solved the above problem.
我如何为这个做的:
<asp:TemplateField HeaderText="Failed Files"
SortExpression="NumFailed">
<ItemTemplate>
<asp:Image ID="Image2" runat="server" ImageUrl="~/NewFolder1/warning_16x16.gif" />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "GetFilesFailed.aspx?id="+Eval("MachineID") %>' Text='<%# Bind("NumFailedFiles") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
的超级链接具有需要格式化数...
the hyperlink has the number which need to be formatted...
推荐答案
使用DataFormat属性:
Use DataFormat property :
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
ReadOnly="True" SortExpression="totaldata" DataFormatString="{0:n3}" />
编辑:对于你的问题使用eval方法的第二个参数的第二部分格式化您的数据:
EDIT : For the second part of your question use Eval method's second parameter to format your data :
<%# Eval("NumFailedFiles", "{0:n3}") %>
那么你的模板将是这样的:
Then your template will be like that :
<asp:TemplateField HeaderText="Failed Files"
SortExpression="NumFailed">
<ItemTemplate>
<asp:Image ID="Image2" runat="server"
ImageUrl="~/NewFolder1/warning_16x16.gif" />
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "GetFilesFailed.aspx?id="+Eval("MachineID") %>'
Text='<%# Eval("NumFailedFiles", "{0:n3}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
这篇关于在GridView控件格式十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!