I am working on a co-workers website, and he mistakenly put up a gridview that shows a TypeID instead of the TypeName. I want to put the actual NAME of the type, instead of it's arbitrary ID number, like he has it. I see he has two "ObjectDataSource"'s on the page -- one for Type and one for Item. Items contains the ID of what TYPE the item is, which is all in the Items datasource. He is pulling this ID to populate the gridview. I want to use that ID to pull the NAME form the other data source, and place that NAME into the gridview for that specific column. Can this be done? Can I use two different datasources on a gridview?
+1
A:
If i'm understanding this right, what you have is two datasources that do this:
1) SELECT ID, Item, ItemTypeID FROM Item
2) SELECT ID, ItemType FROM ItemTypes
And you're wanting the Item name and the Item Type displayed in your grid.
To answer your fundamental question if you can use both sources on the grid: yes. But that's not the most efficient way to perform the operation, as you'd need to be walking the second datasource for every line in the first.
A better way would be to join the two datasources together, and only have one.
Modify the SELECT statement for the first datasrouce to be something along these lines:
SELECT i.ID, i.Item, t.ItemType FROM Item i INNER JOIN ItemTypes t ON i.ItemTypeId = t.ID;
Stephen Wrighton
2008-10-31 16:52:24
Thanks - I figured it out kinda on my own. (well, learning I guess) and I just made a new ObjectDataSource that pulled from both tables. When I modified the existing SQL, I got some errors I didn't understand. Creating a new Datasource solved my issue, but you got me on the right track :)
Kolten
2008-10-31 16:58:47
Oh, i know the error i got - it seems that when using an INNER JOIN for some reason it can't automatically create the INSERT statement. Since this INSERT statement is referenced elsewhere, it bombed.
Kolten
2008-10-31 17:17:32