Link to home
Start Free TrialLog in
Avatar of Steege1
Steege1

asked on

Binding gridview to two datasources

I think this is easy but my brain hurts :( i want to bind a gridview to two different datasources, i am thinking that the best way to do this is to create a new datatable and add both datatables  to the one and bind it to the grid. but i am having problems getting this to work. any ideas  on how to do this and if maybe there is a better solution than doing it this way?
Avatar of dungla
dungla
Flag of Viet Nam image

Why do you need to bind two datasources to the gridview?
Avatar of Steege1
Steege1

ASKER

i have two different datatables that i want to merge for one view, i could put them into seperate views but that doesnt make sense  since the data is very similar. its coming from the same database but different parameters and i really dont want to create a sproc just for this one special occasion. so i figure my best bet would be two make my sproc call that returns the datatables. put them into one and then bind. like i said im not sure if this is the best solution, i.e. putting the two datatables together or if there is a way you can databind of gridview to two differenct sourcs
Hi,

You can combine the 2 results you are getting from DB using queries, you said you have 2 quesries each one on same table but with different paramaters,, so you can do the following:

select * from myTable where column1 = par1 and column2= par1
union
select * from myTable where column1 = par3 and column2= par4


This will return 2 results combined with one DataTable
Avatar of Steege1

ASKER

i am using sp calls so i would prefer not to make a wrapper sp for this
Okay another way ,, is to make you own datatable,, make new datatable add whatever columns to it ,, then bind it by looping through the results from 2 sp,,
Avatar of Steege1

ASKER

do you have any code examples? i understand that this is what i want to do but need a start on how
ASKER CERTIFIED SOLUTION
Avatar of Nasser Hamdan
Nasser Hamdan
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin