Solved

Recreating a dataset based on gridview

Posted on 2007-11-23
2
734 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:Artform04
2 Comments
 
LVL 12

Accepted Solution

by:
needo_jee earned 400 total points
ID: 20340379
if you need to get your datasource back from gridview then you can get it as following
DataTable dt = new DataTable();
dt = (DataTable)GridView1.DataSource;

now dt has all the data which you have bound with gridview.

0
 
LVL 1

Author Comment

by:Artform04
ID: 20345437
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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question