【问题标题】:gridview System.NullReferenceException: Object reference not set to an instance of an object.gridview System.NullReferenceException:对象引用未设置为对象的实例。
【发布时间】:2013-10-23 10:37:16
【问题描述】:

我的网络应用发布时收到错误消息。当我运行该应用程序时,它工作正常。

我正在使用 vs 2010

这是出错的代码行:

  Dim money As String = footer.Cells(1).Text.Replace("£", String.Empty)

目的是查看gridview的页脚,然后删除£符号,使其不再存在

我将 excel 电子表格中的信息行数据绑定到 girdview

Protected Sub GridView5_RowDataBound(ByVal sender As Object, ByVal e As  System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView5.RowDataBound
    If e.Row.RowType = DataControlRowType.Footer Then
        e.Row.Cells(0).Text = "Total"
        e.Row.Cells(1).Text = total.ToString("c")
    End If


End Sub

谁能帮忙

【问题讨论】:

  • 也显示 GridView 标记

标签: asp.net vb.net error-handling vb.net-2010


【解决方案1】:

在这一行:

e.Row.Cells(1).Text = total.ToString("c")

total 在哪里初始化?

如果它没有被初始化,那么当你在这里通过 Cells(1) 访问它时:

Dim money As String = footer.Cells(1).Text.Replace("£", String.Empty)

你会得到 NullReferenceException

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 2022-12-05
    • 1970-01-01
    相关资源
    最近更新 更多