Click here to Skip to main content
15,887,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear friends,

I have a GridView in which i want data from two different tables. say table1 and table2.

I have written a stored procedure which return two tables.

Now i want to add this two tables data in one GridView.

How can i do that???

Thanks in Advance.
:-)
Posted
Comments
Mario Majčica 7-May-12 3:48am    
Are this two tables structurally identical? Are you trying to merge the data between the two? What did you try till now? Make an example.

If thse two tables are similar, you can use a UNION clause.
If they have a foreign key relationship, you could join the two tables and then display them together.

Otherwise, I'm not quite sure why you would want to display unrelated data together in a grid.
 
Share this answer
 
Comments
Espen Harlinn 7-May-12 6:14am    
Good idea :-D
add this two tables data in one GridView
One of the ways: Create a new datatable - third one. Add data from first & second to it.
First add columns of datatable 1 & then datatable 2. Next, add data from each tables to this one.
Once done, use the new datatable as a datasource for grid.

For a similar schema datatable, use DataTable.Merge Method[^]
 
Share this answer
 
Comments
Espen Harlinn 7-May-12 6:14am    
Good points :-D
 
Share this answer
 
Comments
Srinivas Reddy 30-Jan-14 7:42am    
How to bind the multipletables to the gridview in asp.net?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900