Solved

Recreating a dataset based on gridview

Posted on 2007-11-23
2
735 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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