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

  • Home
  • SEARCH
  • 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 6675355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:43+00:00 2026-05-26T03:50:43+00:00

class A { int ID; B ClassB; } class B { string Title; }

  • 0
class A 
{ 
  int ID; 
  B ClassB; 
}

class B 
{ 
  string Title; 
}

Using the above mock classes as examples – I have a dynamically created GridView. To this I bind (add to the Columns collection) X number of BoundFields and then assign a collection to the DataSource, however, my sub objects are not binding.

The DataField property of the BoundFields is set to “ClassB.Title” and the DataSource is a collection of objects of type A but it keeps throwing the exception “A field or property with the name ‘ClassB.Title’ was not found on the selected data source. “

Any thoughts why?

Cheers

  • 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-05-26T03:50:44+00:00Added an answer on May 26, 2026 at 3:50 am

    This is because BoundField uses reflection to evaluate object properties – obviously, class A does not have a property called ClassB.Title and hence the issue.

    You can use template field to work around this issue. For example,

    <asp:templatefield headertext="SomeColumn">
         <itemtemplate>
              <%#Eval("ClassB.Title")%>
         </itemtemplate>
    </asp:templatefield>
    

    Note that instead of using typical template-field markup such as below, you may use strongly typed expressions such as

    <asp:templatefield headertext="SomeColumn">
         <itemtemplate>
              <%# ((A)(Container.DataItem)).ClassB.Title  %>
         </itemtemplate>
    </asp:templatefield>
    

    Note the type-casting of data-item to your specific class (A).

    EDIT: yet another alternative is to build your own BoundField that can do nested property lookup – for example:

    public class MyBoundField : BoundField
    {
       protected override object GetValue(Control controlContainer)
       {
          string dataField = this.DataField;
          if (string.IsNullOrEmpty(dataField)) { return null; }
          if (!dataField.Contains('.'))
          {
             // use base implemenation
             return base.GetValue(controlContainer);
          }
    
          // design time support
          if (base.DesignMode)
          {
            return this.GetDesignTimeValue();
          }
    
          // Use data-binder to evaluate nested property look-ups
          return DataBinder.Eval(controlContainer, dataField);
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: class MyObj { int Id; string Name; string Location; }
#include <iostream> #include <string> using namespace std; class BookData { string Title; int Qty;
I have: class Foo { int a; int b; std::string s; char d; };
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
I have a class A { public int X; public double Y; public string
public class Command { public int CommandId { get; set; } public string Title
I have two classes defined as such: public class Questionnaire { public int QuestionnaireID
How do something like that: Class Car: string Name, int year Class SUV:Car; SUV
here's the code: class Acount { int sum ; String owner ; //these seem
Consider the following simplified objects and relationships: public class Job{ int JobId; String name;

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.