0
我有一个模板字段,如下面的GridView控件所示。输入字符串与GridView中的TemplateField格式不正确
<asp:TemplateField HeaderText="Total" SortExpression="CYTotal">
<ItemTemplate>
<asp:Label ID="lblCYTotal" runat="server" MaxLength="20" Width="30" ReadOnly ="true"
Text = '<%# Bind("CYTotal","{0:#,##0}") %>' Font-Names="Tahoma" Font-Size="8pt"> </asp:Label>
</ItemTemplate>
<HeaderStyle Width="30px" Font-Names="Tahoma" Font-Size="8pt"/>
<ItemStyle Width="30px" HorizontalAlign="Right" />
</asp:TemplateField>
我设置在RowDataBound事件模板字段内标签的格式如下图所示
if (accountTextBox.Text != "Gross Margin")
{
lblCYTotal.Text = String.Format("{0:$#,##0}", Convert.ToDecimal(lblCYTotal.Text));
}
else if (accountTextBox.Text == "Gross Margin")
{
lblCYTotal.Text = String.Format("{0:P0}", Convert.ToDecimal(lblCYTotal.Text));
}
,然后在RowUpdating事件中,我使用下面的代码,但它是给我的错误“*输入字符串不正确forma *吨”。 我试着用下面的“替换”去除“%”符号,但没有运气。我也尝试使用NumberStyles.Currency和NumberStyles.Float。
decimal currency = decimal.Parse(lblCYTotal.Text.Replace("%",""), NumberStyles.Any);
任何帮助将不胜感激!
为什么你不取代$?因为从你的代码看,它可能在你的文本框中可能为$。如果是的话,它肯定会给你一个例外。 –
感谢Manish,我应该提到我曾尝试更换$和%但仍然得到相同的错误。 – sam
好吧,但是你没有提到你在哪一行出错,以及在出错时你的文本框是什么。 –