use data from second sqldatasource in gridview itemtemplate?

G

Guest

I need to convert a CompanyId in one table to Company Name from another
table for an ItemTemplate. I thought I would just add another SqlDataSource
but not sure how to eval with the CompanyId parameter for the where clause in
the select.

Any clues would be appreciated.
 
G

Guest

Would a SQL join statement be what you are looking for? Or are you looking to
select first a row of the GridView and then execute a sub query based on the
selected Company ID?
 
G

Guest

Well, generally I'm trying to solve the issue of displaying relational data
in a GridView. Given table "commuters" and table "OfficeParks", where a
customer row has a key OfficeParkId that links to OfficeParks. I would like
to show the OfficePark name in the Gridview.

I guess this could be solved with a join but not sure what the
EditItemTemplate would look like for this. For the ItemTemplate I was
thinking more along the lines of having a Label control Text value set to the
OfficePark name pulled using the OfficeParkId from the commuters table using
a second SqlDataSource.
 
G

Guest

For the Itemtemplate, I think that the SQL join statement would be adequate
and you only need one datasource to do that (let’s say “datasource1â€). As
for the EditItemTempalte, if you intend to allow changing the OfficeParkID
then you can implement a dropdownlist during the edit template that relies on
a separate datasource object (datasource2) that retrieves all available
selections for that customer. Upon edit you would grap the new selectedValue
of the dropdownlist (the new OfficeParkID) and update “datasource1†with the
customer’s record.

If you need the code to implement a GridView that contains elements from
several datatables look at the source code of this demo from my website:

http://www.webswapp.com/codesamples/aspnet20/dependentlists/gridview.aspx
 
G

Guest

Thanks Phillip, you're a prince! I implemented the join solution while you
were typing this up, I still have to code the EditItemTemplate with dropdown,
will have a look at your code for how to update the datasource1 after user
selects a new dropdownlist entry and commits.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top