how to tie the Objectdatasource value to the label in itemtemplate?

dkim18
dkim18 used Ask the Experts™
on
Hi,

Can I tie the value of objectdatasource to a label in itemtemplate of detailsView?

The detailsview was tied to a record which has a FK.
So right now, it displays the integer.
I want to use the objectdatasource to lookup that FK and return a meaningful value.

I was able to do that with edittemplate and inserttemplate.

If I have this objectdatasource returns a DataTable, how can I bind that to a label in itemtemplate??

I guess I could try to do this in beind-the-code page but is there a way to do this without doing it in the behind-the-code?
I want to do it in the inlinecode,just like i did with insert and updatetemplate?

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The key there is to update the objectDataSource to pull the meaningful value with a left outter join.  For example if I had a table that FK and a meaningful value in another table... For this example I'll use a table that has a FK of WorkoutPersonID (workoutTracking) - but I want to pull the value of the actual WorkoutPerson in another table.  By using left outer join I can do that in my select statement, and then just bind to the workoutperson.

After that in the Detailsview you can just Eval("WorkoutPerson") just like you do the UniqueID
SELECT WorkoutTracking.WorkoutPersonID, WorkoutPerson.WorkoutPerson FROM WorkoutPerson INNER JOIN WorkoutTracking ON WorkoutPerson.WorkoutPersonID = WorkoutTracking.WorkoutPersonID

Open in new window

Commented:
Er excuse me, it's early - it's not a left outter join, it's an inner join.  But the point is still there, just the syntax on the join.

Author

Commented:
I am sorry.
I was asking if there is a way to bind the objectdatasource.
I guess you are saying I should take care of converting the id to a value in sql and and don't worry about converting the id and try to bind back to the label.
Commented:
Exactly, it's just extra work.  It's kind of necessary in the edit item templates, and the insert templates when using dropdownlists because it needs to pull ALL the potential values... but in the select stage where it's just displaying the data (one record) and it's only need is to display it, just pull the value in your original select statement :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial