Keeping DataTable in Viewstate

In order to persist a datatable, you can easily add it to the Viewstate, by creating a property in your class:
What I do in many circumstances, is, like the last post said, pass the DataTable to viewstate as a property of the class:

Private Property EmployeeData() As System.Data.DataTable
        Get
            Dim o As Object = ViewState("EmployeeData")
            If o Is Nothing Then
                Return Nothing
            Else
                Return o
            End If
        End Get
        Set(ByVal value As System.Data.DataTable)
            ViewState("EmployeeData") = value
        End Set
    End Property

Now, whenever you need to repopulate, or add a row, remove a row, etc – just refer to the property “EmployeeData”

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>