Sub DBGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) 
    Dim TaxTotal As Double
    Select Case e.Item.ItemType
        Case ListItemType.AlternatingItem,ListItemType.Item
               TaxTotal += Cdbl(e.Item.Cells(3).Text)
      
        Case ListItemType.Footer
        e.Item.Cells(2).Text = "合计:"
        e.Item.Cells(3).Text = TaxTotal
    End Select
    End Sub
Input string was not in a correct format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format.Source Error: 
Line 116:     Select Case e.Item.ItemType
Line 117:         Case ListItemType.AlternatingItem,ListItemType.Item
Line 118:               TaxTotal = TaxTotal + Cdbl(e.Item.Cells(3).Text)
Line 119:       
Line 120:         Case ListItemType.Footer
 

解决方案 »

  1.   

    检查e.Item.Cells(3).Text可不可以转换为double
      

  2.   

    what does your template look like? did you check what is in e.Item.Cells(3)?  Response.Write("***" & e.Item.Cells(3).Text & "***")
     if (IsNumeric(e.Item.Cells(3).Text))
        TaxTotal += Cdbl(e.Item.Cells(3).Text)
      

  3.   

    System.Web.UI.WebControls.DataGridItemEventArgs) 
        Dim TaxTotal As Double
        Select Case e.Item.ItemType
            Case ListItemType.AlternatingItem,ListItemType.Item
                   TaxTotal += double.Parse(e.Item.Cells(3).Text);///e.Item.Cells(3).Text是数字不为空
          
            Case ListItemType.Footer
            e.Item.Cells(2).Text = "合计:"
            e.Item.Cells(3).Text = TaxTotal.toString();//应该转换为STRING型
        End Select
        End Sub
      

  4.   

    运行结果
    我的e.Item.Cells(3).Text是空字符(???)但实际上是有数字的,应该怎么写啊??
      

  5.   

    1 e.Item.Cells(3).Text是否为有效值;
    2 检查给e.Item.Cells(3).Text赋值的语句是否ok
      

  6.   

    118行不报错了,但
    Case ListItemType.Footer
            e.Item.Cells(2).Text = "合计:"
            e.Item.Cells(3).Text = TaxTotal.ToString最后合计数怎么还是0啊?
      

  7.   

    Dim TaxTotal As DoubleTaxTotal 改成用全局变量