0

I'm sure this is easy, but I'm seeming to have a brainfart or something and can't find any ways to do this....

I have a gridview, which is displaying data from an objectdatasource/tableadapter. One of the columns in the gridview is a UserID. Instead of displaying the UserID, I want to display the corresponding Username from another objectdatasource based on that UserID. I swear I need to do something in the itemtemplate, but I'm not seeing it. Can someone point me in the right direction?

Thanks!

3
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by nikkiH
0

If you are using the GUI to make your object data source then you will need to write a custom sql script to join the 2 tables on the user id so the username field will be available in your grid view

0

Thanks, that's what I was afraid of. Can't I do something in the gridview or row binding or something, too?

0

select * from table1 t1 join t2 on t1.userID = t2.userID

when you are making your data source just use the write your own sql query option, it isnt rocket science! be not afraid!

0

Unless you're stuck with someone else's DAL, that is. ;)

You can write custom code to get the value, but it's a serious pain in the behind and isn't actually binding. You have to write custom code in the onItemDataBound event, I believe.

If you can write your own query, it's a LOT simpler.

0

Thanks all...yes, I can write my own query, and that's what I ended up doing. I was just trying to abstract it out as much as possible, without having to make custom queries, stored procs, etc. for each different thing I wanted to display. I think I've done stuff before with the onItemDataBound event or something like it, so maybe I'll look into that again. Thanks again!

0

You don't have to display every column you select.
I use views with a bunch of columns as my datasource, and they work for several different grids.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.