在GridView中如何格式化Money型字段?
在GridView中如何格式化Money型字段(downmoon)?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="PKID"
DataMember="DefaultView" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="PKID" HeaderText="PKID" InsertVisible="False" ReadOnly="True"
SortExpression="PKID" />
<asp:TemplateField>
<HeaderTemplate>
amount</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtMoney" Text='<%# Decimal.Parse(DataBinder.Eval(Container.DataItem,"amount").ToString())%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TestID" HeaderText="TestID" SortExpression="TestID" />
<asp:BoundField DataField="testString" HeaderText="testString" SortExpression="testString" />
</Columns>
</asp:GridView>
DataMember="DefaultView" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="PKID" HeaderText="PKID" InsertVisible="False" ReadOnly="True"
SortExpression="PKID" />
<asp:TemplateField>
<HeaderTemplate>
amount</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="txtMoney" Text='<%# Decimal.Parse(DataBinder.Eval(Container.DataItem,"amount").ToString())%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TestID" HeaderText="TestID" SortExpression="TestID" />
<asp:BoundField DataField="testString" HeaderText="testString" SortExpression="testString" />
</Columns>
</asp:GridView>
这段代码中,
amount为Money型字段,无论如何只能显示成
1234.5600
而不能显示成
1,234.56
用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
也不行!
后来在MSDN上找到了答案
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
关键在于HtmlEncode="False"
http://blogs.msdn.com/danielfe/archive/2006/02/08/527628.aspx