How to bind a value in GridView to other data?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 33
Reputation: edmicman is an unknown quantity at this point 
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

How to bind a value in GridView to other data?

 
0
  #1
Feb 8th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

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

 
0
  #2
Feb 8th, 2007
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
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 33
Reputation: edmicman is an unknown quantity at this point 
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

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

 
0
  #3
Feb 9th, 2007
Thanks, that's what I was afraid of. Can't I do something in the gridview or row binding or something, too?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 130
Reputation: sedgey is on a distinguished road 
Solved Threads: 8
sedgey's Avatar
sedgey sedgey is offline Offline
Junior Poster

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

 
0
  #4
Feb 9th, 2007
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.
David Ridgway: so little daylight, too much caffeine
MCSD MCAD MCSE
http://web2asp.net
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

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

 
0
  #5
Feb 13th, 2007
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.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 33
Reputation: edmicman is an unknown quantity at this point 
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

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

 
0
  #6
Feb 13th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

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

 
0
  #7
Feb 13th, 2007
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.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC