我有一个显示数据库信息的gridview,我希望将结果转换为货币格式。 这是我试图转换的行:
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OrderTotal", "{0:c}") %>'></asp:Label>
这不起作用,并且没有错误。只有整数显示在gridview中。 有没有办法在.aspx页面中执行此操作?如果没有,我需要做什么才能将每一行转换为Money格式?
全部谢谢!
编辑: 整个Gridview代码:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="4" DataKeyNames="OrderID"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="100%"
AllowPaging="True" style="margin-right: 3px" PageSize="50">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False"
CommandName="Select" Text=">> "></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Order #" InsertVisible="False"
SortExpression="OrderID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Bind("OrderID") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="OrderDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OrderDate") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="OrderAccount" HeaderText="Ordered By"
SortExpression="OrderAccount" />
<asp:BoundField DataField="OrderCostCentre" HeaderText="Cost Centre"
SortExpression="OrderCostCentre" />
<asp:TemplateField HeaderText="Total" SortExpression="OrderTotal">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("OrderTotal", "{0:c}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("OrderTotal").ToString("C") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
答案 0 :(得分:1)
<%#Eval("OrderTotal", "{0:c}")%>
答案 1 :(得分:1)
如果出现问题,请检查OrderTotal
是否为非数字类型。将它转换为数字,它应该工作