Link to home
Start Free TrialLog in
Avatar of Artform04
Artform04

asked on

Recreating a dataset based on gridview

Hi guys,

I need to create a dataset that mimicks the data I have in a gridview.  This is part of a custom sorting problem I am having.  

So far i have the code below, but it doesnt return the data that I see on my gridview.  Could someone please let me know how to copy the data??

Thanks in advance.
Phil

Dim dsCurrent As New DataSet
        dsCurrent.Tables.Add()
        For i As Integer = 0 To GridView1.Columns.Count - 1
            dsCurrent.Tables(0).Columns.Add()
        Next
 
        For Each r As UI.WebControls.GridViewRow In GridView1.Rows
            dsCurrent.Tables(0).Rows.Add()
            For i As Integer = 0 To r.Cells.Count - 1
                dsCurrent.Tables(0).Rows(dsCurrent.Tables(0).Rows.Count - 1).Item(i) = r.DataItem(i)
            Next
        Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Munawar Hussain
Munawar Hussain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Artform04
Artform04

ASKER

Ive ended up just using session vars to store the dataset.  The datasource becomes inaccessible once the page has been bound and Im trying to access it at a later stage. thanks for the help anyway.. have some points