3

I have a rather tricky situation. I am using an ASP:Repeater which is bound to a SOAP datasource returning the below object structure.

Path: Array[6]
0: Object
   Direction: "Departing"
   Message: ""
   Operator: "myciti"
   RouteColor: "#a7a9ac"
   RouteName: "Airport"
       Stop: Object
           Name: "JFK"
           Location: Object
   Name: "Airport"
   __proto__: Object
   Time: "07:10"
   Type: ""
   Vehicle: ""

I can easily access all the first tier variables, such as "Time" by using Eval as such:

  <%# Eval("Time")%>

My problem is how would I access the nested objects still using EVAL from the ASPX page? For example how would I get to the "Name" value of the "Stop" object within this array which has the value "JFK"?

2 Answers 2

6

Try: <%# Eval("Stop.Name")%>

Sign up to request clarification or add additional context in comments.

Comments

3

Eval is just a shortcut to obtain a property by name. It won't help you in some cases. Like for example, what if your object RouteName sometimes returns null.

You need to use:

<%# Container.DataItem.RouteName.Stop.Name %>

Container.DataItem is an object so you can access just about any property from it.

A better way would be to Cast that object into a more meaningful instance:

<%# Ctype(Container.DataItem, ReturnedSOAPObjectRecord).RouteName.Stop.Name %>

This method gives you the ability to check for nulls.

<%# IF(Ctype(Container.DataItem, ReturnedSOAPObjectRecord).RouteName IsNot Nothing, Ctype(Container.DataItem, ReturnedSOAPObjectRecord).RouteName.Stop.Name, "No Stop" %>

2 Comments

Thanks for the additional info.
Carlos, I was just reading through your methods and think you may have made a syntax error in your third method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.