Convert Grid View datasource to datatable

I ahve a grid view which has its inital bind done to a datatable.

I need to extract the datasource back into a datatable. When I try the following the datasource shows empty(Nothing)

 Dim dt As DataTable = DirectCast(gvSelect.DataSource, DataTable)

On my page load I get data using ADO.NET
and then assign the datatable as the datasource of the gridview
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I use C#....and use dataset to get table from database
And  DataTable can get tables from dataset easily.
      Datatable dt = dataset1.Table["Table_Name"];
About datadridView,
      DataTable dt1 = (DataTable)dataGridView1.Datasource;
AshokSr. Software EngineerCommented:
Code you are using to convert to DataTable is correct.

When assigning DataTable to gvSelect, use

gvSelect.DataSource = dt


countrymeisterAuthor Commented:

I am already doing that when assigning a datosource to the datagrid.

I want to get back the datttable and the following does not work
Dim dt As DataTable = DirectCast(gvSelect.DataSource, DataTable)

In debug mode gvSelect.DataSource = Nothing
I think in ASP.NET, you have to save the datatable to the Session to be able to use it after postback.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.