| | |
How to bind a value in GridView to other data?
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
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!
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!
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
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!
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.
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.

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/
Bored? Visit http://www.kaelisspace.com/
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!
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.
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/
Bored? Visit http://www.kaelisspace.com/
![]() |
Similar Threads
- Gridview Paging Problem. (C#)
- datagrid-recordset (Visual Basic 4 / 5 / 6)
- Age sorting in Gridview urgent please >>>>>>>>>>> (ASP.NET)
- Help! Emergendy Case (ASP.NET)
- C# .NET Gridview (C#)
- Special formatting of a GridView... (ASP.NET)
- ComboBox bind data problem (VB.NET)
- GridView Edit and Delete buttons (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Current month name
- Next Thread: .NET ASPX worker process locks images referenced by PDF
| Thread Tools | Search this Thread |
.net 3.5 ajax alltypeofvideos appliances asp asp.net bc30451 beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox login microsoft mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





