locked
how to get data from gridview footer to display in textbox outside the gridview? RRS feed

  • Question

  • hi,

    Is anyone know how to get data from gridview footer and show it in textbox outside the gridview. Here I give the example, I make a total price in gridview footer. Then I want to call back the total and show the total in a textbox. The problem is I always get this error 

    Object reference not set to an instance of an object.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Line 68: 
    Line 69:             Dim c As Integer = 0
    Line 70:             Dim j As String = CType(GridView3.Rows(c).Cells(3).FindControl("Total:"), TextBox).Text
    Line 71:             TextBox2.Text = j
    Line 72: 

    My coding is like this

     Protected Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView3.RowDataBound
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim rowTotal As Decimal = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "SPA"))
                subTotal = subTotal + rowTotal
            End If
    
            If e.Row.RowType = DataControlRowType.Footer Then
                e.Row.Cells(3).Text = "Total:"
                e.Row.Cells(4).Text = subTotal.ToString("c")
    
                Dim c As Integer = 0
                Dim j As String = CType(GridView3.Rows(c).Cells(3).FindControl("Total:"), TextBox).Text
                TextBox2.Text = j
    
            End If
        End Sub

    I really hope that someone could help me with this....thank u..

    Wednesday, September 11, 2013 5:52 PM

Answers