Solved

Recreating a dataset based on gridview

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now