944,129 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 9671
  • ASP.NET RSS
Feb 8th, 2007
0

How to bind a value in GridView to other data?

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
edmicman is offline Offline
33 posts
since Oct 2005
Feb 8th, 2007
0

Re: How to bind a value in GridView to other data?

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
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
Feb 9th, 2007
0

Re: How to bind a value in GridView to other data?

Thanks, that's what I was afraid of. Can't I do something in the gridview or row binding or something, too?
Reputation Points: 10
Solved Threads: 0
Light Poster
edmicman is offline Offline
33 posts
since Oct 2005
Feb 9th, 2007
0

Re: How to bind a value in GridView to other data?

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!
Last edited by sedgey; Feb 9th, 2007 at 6:51 pm.
Reputation Points: 68
Solved Threads: 9
Junior Poster
sedgey is offline Offline
130 posts
since Jan 2007
Feb 13th, 2007
0

Re: How to bind a value in GridView to other data?

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.
Reputation Points: 13
Solved Threads: 4
Junior Poster in Training
nikkiH is offline Offline
79 posts
since Dec 2006
Feb 13th, 2007
0

Re: How to bind a value in GridView to other data?

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!
Reputation Points: 10
Solved Threads: 0
Light Poster
edmicman is offline Offline
33 posts
since Oct 2005
Feb 13th, 2007
0

Re: How to bind a value in GridView to other data?

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.
Reputation Points: 13
Solved Threads: 4
Junior Poster in Training
nikkiH is offline Offline
79 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Current month name
Next Thread in ASP.NET Forum Timeline: .NET ASPX worker process locks images referenced by PDF





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC