User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 427,025 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,550 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4115 | Replies: 6
Reply
Join Date: Oct 2005
Posts: 27
Reputation: edmicman is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

How to bind a value in GridView to other data?

  #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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation: sedgey is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
sedgey sedgey is offline Offline
Junior Poster in Training

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

  #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
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
Reply With Quote  
Join Date: Oct 2005
Posts: 27
Reputation: edmicman is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

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

  #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  
Join Date: Jan 2007
Location: Japan
Posts: 70
Reputation: sedgey is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
sedgey sedgey is offline Offline
Junior Poster in Training

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

  #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 5:51 pm.
sedgey: so little daylight, too much caffeine
MCSD MCAD MCSE
http://www.thefriendlybuilder.co.uk,
http://www.sheetmusicdirect.com
Reply With Quote  
Join Date: Dec 2006
Location: Near Chicago
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Rep Power: 2
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?

  #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  
Join Date: Oct 2005
Posts: 27
Reputation: edmicman is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
edmicman's Avatar
edmicman edmicman is offline Offline
Light Poster

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

  #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  
Join Date: Dec 2006
Location: Near Chicago
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Rep Power: 2
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?

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:50 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC