输入字符串的格式不正确

时间:2011-11-03 12:33:48

标签: asp.net

    protected void CustomersGridView_DataBound(Object sender, EventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            decimal rowTotal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "DC_No_Decimal"));
            if (e.Row.DataItemIndex >= inderGrid.PageIndex * inderGrid.PageSize && e.Row.DataItemIndex < inderGrid.PageIndex * inderGrid.PageSize + inderGrid.PageSize)
            {
                grdTotal = grdTotal + rowTotal;
            }
        }
        else if (e.Row.RowType == DataControlRowType.Footer && inderGrid.PageCount == inderGrid.PageIndex + 1)
        {
            for (int i = 0; i < inderGrid.Rows.Count; i++)
            {
                decimal currentRowCellVal = Convert.ToDecimal(inderGrid.Rows[i].Cells[3].Text);
                grdTotal += currentRowCellVal;
            }
            e.Row.Cells[3].Text = grdTotal.ToString("c");
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {       
                e.Row.Cells[0].Text = "Totals:";
                // for the Footer, display the running totals
                e.Row.Cells[3].Text = grdTotal.ToString("0.00");
                // e.Row.Cells[2].Text = quantityTotal.ToString("d");        
                e.Row.Cells[1].HorizontalAlign = e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;
                e.Row.Font.Bold = true;
        }
   }

此网格的目的是在网格的最后一页中显示总计。当我要访问页面页面时出现错误:

  

输入字符串的格式不正确。

在网格的最后一页中,我需要在单元格[3]

的网格中的所有页面的总数

2 个答案:

答案 0 :(得分:1)

你说你的错误在:

e.Row.Cells[3].Text = grdTotal.ToString("0.00");

你必须使用格式化程序:

e.Row.Cells[3].Text =  String.Format("{0:C}", grdTotal);

e.Row.Cells[3].Text = grdTotal.ToString("C", CultureInfo.CurrentCulture);

检查grdTotal是否为小数......

查看:MSDN

答案 1 :(得分:0)

我认为你的问题在于这一行

e.Row.Cells[3].Text = grdTotal.ToString("0.00"); 

我假设你的grdTotal变量是小数,使用“0.00”不是有效的格式化程序。

在此处查看MSDN网站http://msdn.microsoft.com/en-us/library/system.decimal.tostring.aspx

至少你可以尝试e.Row.Cells[3].Text = grdTotal.ToString();

相关问题