Best practice for combining typed DataTables for display in GridView

J

J055

Hi

I need to search a number of DataTables within a DataSet (with some
relationships) and then display the filtered results in a GridView. The
Columns that need to be displayed come from 2 of the tables but the search
needs check 3 or 4 tables. Do I need to create a new DataTable which has the
columns from both the tables so I can display in the Gridview or can I get
the columns somehow from the DataSet without creating a new table?

I feel like I'm missing something when it comes to getting the benefits of
DataTable relationships in terms of combining them for display in a flat
GridView.

Any ideas suggestions, pointers to examples would be appreciated.

Thanks
Andrew
 
E

Eliyahu Goldin

The simple answer is make another table.

GridView gets data from a datasource. Datasource is an object. Two tables
are two objects. You have to make one single object out of columns you need
and databind to it. An obvious way is to make another DataTable, but there
could be reasons for choosing different classes.
 
J

J055

Thanks Eliyahu

That's kind of what I was coming round to thinking. If I create a DataTable
without a TableAdapter then I can populate it with the data I need from the
results search and hopefully without too much extra typing!

Thanks again
Andrew


Eliyahu Goldin said:
The simple answer is make another table.

GridView gets data from a datasource. Datasource is an object. Two tables
are two objects. You have to make one single object out of columns you
need
and databind to it. An obvious way is to make another DataTable, but there
could be reasons for choosing different classes.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


J055 said:
Hi

I need to search a number of DataTables within a DataSet (with some
relationships) and then display the filtered results in a GridView. The
Columns that need to be displayed come from 2 of the tables but the
search
needs check 3 or 4 tables. Do I need to create a new DataTable which has the
columns from both the tables so I can display in the Gridview or can I
get
the columns somehow from the DataSet without creating a new table?

I feel like I'm missing something when it comes to getting the benefits
of
DataTable relationships in terms of combining them for display in a flat
GridView.

Any ideas suggestions, pointers to examples would be appreciated.

Thanks
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top