1

I have 2 C# classes:

public class Course
{
    public string Title{get;set;}
    public int Code {get;set;}
}

public class Student 
{
    public int Id{get;set;}
    public string Surname{get;set;}
    public Course Course {get;set}
...
}

As you can see the Student class contains a reference to Course. I have a method in my application to return me a student object. In my ASP.NET .aspx file I have the following code:

...

<columns>
<asp:BoundField DataField="Id" HeaderText="Id"/>
<asp:BoundField DataField="Surname" HeaderText="Surname"/>
...
</columns>

...

How do I access the values of the Course property in the Student class (i.e. how do I get the course code and title for the current student).

1
  • My comment is not related to your question. You can rename the third property in Student class to avoid ambiguity in future. Commented May 21, 2011 at 9:46

1 Answer 1

3

You may find the following blog post useful. Or as an alternative you could use a TemplateField:

<asp:TemplateField HeaderText="Course Title">
    <ItemTemplate>
        <%# Eval("Course.Title") %>
    </ItemTemplate>
</asp:TemplateField>
Sign up to request clarification or add additional context in comments.

Comments

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.