Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:13:22+00:00 2026-06-02T06:13:22+00:00

Ok, let’s imagine I have an object like this: public class User { public

  • 0

Ok, let’s imagine I have an object like this:

public class User {
    public int ID { get; set; }
    public String Name { get; set; }
    public String Surname { get; set; }
    public String Description { get; set; }
    public Location Location { get; set; }
}

Notice that the last property, is a Location type object. Let’s see the Location object:

public class Location {
    public String ID { get; set; }
    public String Address { get; set; }
    public String PostCode { get; set; }
}

Now I want to show a list of users in a gridview but instead of feeding it with a datareader or any data object, I want to use a List of Users Collection, so I call a method that gives me a List collection and databind the gridview like this:

gvUsers.DataSource = getUsers(); // This returns a List<User> collection.
gvUsers.DataBind();

Now, I’ve used some BoundFields and Templatefields to show the data and it works without problems, like this:

<asp:GridView ID="gvUsers" runat="server" AutoGenerateColumns="False" >
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:TemplateField HeaderText="Surname">
            <ItemTemplate>
                <asp:Label ID="lbSurname" runat="server" Text='<%# Eval("Surname") %>'></asp:Label>
                <asp:HiddenField ID="hdnUserId" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "ID") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

The problem comes if I try to access the Location object properties, imagine this in the template field:

<asp:HiddenField ID="hdnLocationName" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "Location.PostCode") %>' />

That doesn’t work.

I don’t know if there is a way of doing that to show it using a template field. I also wonder if there is a way of doing it using a BoundField.

If it cannot be done just using the FrontEnd, can be done in the Backend in the gridView databound somehow? Should I use LINQ and set it on the select instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:13:22+00:00Added an answer on June 2, 2026 at 6:13 am

    The Law of Demter applies. In short, you’ll have to make Postcode a property of user if you want to bind to it like that.

    This page gives a nice example of Law of Demeter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's imagine I have a Java class of the type: public class MyClass {
Let's say that I have a set of relations that looks like this: relations
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say I have one class User, and it has a property of type
Let's say I have table with column 'URL' whrere I store urls like this
Let's suppose I have this piece of code. foreach(string value in myList) { string
Let's suppose we have: Class Foo{ int x,y; int setFoo(); } int Foo::setFoo(){ return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.