如何在gridview中格式化货币格式的值

时间:2011-04-16 02:29:23

标签: asp.net

protected void LineItemGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     Label lbl3 = (Label)e.Row.FindControl("lbltotal");
     if (lbl3 != null)
     {
         lbl3.Text = college.Student.Activity[e.Row.RowIndex].Mark1.ToString();
         total += decimal.Parse(lbl3.Text);
     }
}

在aspx页面中

<asp:TemplateField HeaderText="Total"  HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Right" HeaderStyle-Width="120px" HeaderStyle-HorizontalAlign="Right">

       

                                  

  

2 个答案:

答案 0 :(得分:0)

格式字符串为“c”。

invoicetransmit.Invoice.LineItem[e.Row.RowIndex].TotalNetAmount.ToString("c");

答案 1 :(得分:0)

protected void LineItemGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
     Label lbl3 = (Label)e.Row.FindControl("lbltotal");
     if (lbl3 != null)
     {
         lbl3.Text = college.Student.Activity[e.Row.RowIndex].Mark1.ToString("c");
         total += decimal.Parse(college.Student.Activity[e.Row.RowIndex].Mark1.ToString());
     }
}