如何在 aspx 页面的 TemplateField 中添加 DataFormatString?

How to add DataFormatString in a TemplateField in aspx page?

我在 aspx 页面中使用 Gridview。 更具体地说,在网格视图中,我正在处理名为 Price

的特定列

gridview 中的价格列值示例应如下所示:

 Price
 1.50 AUD
10.00 AUD
15.55 AUD
100.50 AUD

为了达到这个效果,这是我在aspx文件中尝试过的:

<asp:TemplateField HeaderText="Price" DataFormatString="{0} AUD" >
         <ItemTemplate>
          <asp:TextBox ID ="TextBox1" runat="server" DataField="Product_Price" Text='<%#Eval("Price")%>' />
          <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Numbers with decimals only" ControlToValidate="TextBox1" ValidationExpression="^[0-9]+(\.[0-9][0-9]?)?"></asp:RegularExpressionValidator>
          <asp:Button ID ="Button1" runat="server" OnClick="Update_Click" CommandArgument="Button7" CommandName="Update"  Text="Update" />
          </ItemTemplate>
          </asp:TemplateField>

当我将鼠标光标放在 DataFormatString 语法上时,显示的错误消息如下:

Validation(ASP.NET): Attribute 'DataFormatString' is not a valid attribute of element 'TemplateField'

我哪里弄错了?

如果提供适当的解决方案语法,将会很有帮助。

尝试

<asp:TextBox ID ="TextBox1" runat="server" DataField="Product_Price" Text='<%#Eval("Price","{0:c}")%>' />