尝试从网格视图文本框中获取总计

时间:2014-05-25 03:47:40

标签: asp.net vb.net gridview

我想从文本更改事件中的网格视图文本框中获取值,但是出现错误 对象引用不是对象

的实例的设置
Protected Sub onDebitChange(ByVal sender As Object, ByVal e As EventArgs)
    Dim a, b As Integer

    With GridView3
        Dim rows As Integer = .Rows.Count
        For i As Integer = 0 To rows - 1
            Dim txtDebit As TextBox = CType(GridView3.Rows(i).FindControl("TotalDebit"), TextBox)

            a = Val(txtDebit.Text)

            b += a
        Next

        DebitBalance.Text = b
    End With
End Sub

我也尝试过每个循环,但错误是一样的 请帮忙

1 个答案:

答案 0 :(得分:0)

您需要正确设置ItemTemplate控件的名称,在onDebitChange方法中请将控件名称修复为“借记”而不是“TotalDebit”:

Dim txtDebit As TextBox = CType(GridView3.Rows(i).FindControl("Debit"), TextBox)

希望这有帮助。