473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataGrid Binding to Complex Custom Collection

I'm having trouble figuring this problem out and every example out
there deals with simple objects within a custom collection. Take this
example:

public class ComplexClass
{
private int id;
private InnerClass anotherOne;

public int ID
{
get { return id; }
}
public InnerClass AnotherOne
{
get { return anotherOne; }
}
}

public class InnerClass
{
private int id;
private string name;

public int ID
{
get { return id; }
}
public string Name
{
get { return name; }
}
}

then I have a
public class ComplexCustomCollection : CollectionBase
that contains a list of ComplexClass objects.

Now in my Custom Control, I have a DataGrid that I want to bind to
this ComplexCustomCollection.

When creating columns, I have something like:

BoundColumn column = new BoundColumn();
column.DataField = "ID";
column.HeaderText = "ID #";
myGrid.Columns.Add(column);

column = new BoundColumn();
column.DataField = "AnotherOne.Name"; // just a guess
column.HeaderText = "Another Name";
myGrid.Columns.Add(column);

myGrid.DataSource = myComplexCustomCollection;
myGrid.DataBind();
Which, when ran results in:
A field or property with the name 'AnotherOne.Name' was not found on
the selected datasource.
How can I bind to that inner class's properties?
Any help would be much appreciated. Thanks in advance...
Nov 17 '05 #1
1 2207
Hi,

DataGrid trys to find Property "AnotherOne.Name". But your class
"ComplexClass" has propery "AnotherOne"!
You have to create Property "AnotherOne_Name"

public class ComplexClass
{
...
public string AnotherOne_Name
{
return anotherOne.Name;
}
...
}

Then for each item of the myComplexCustomCollection you will be able to find
Property "AnotherOne_Name".
This Property will show to you name of the class "AnotherOne".
Try to do it.

bye

The Best Regards,
Web Developer
Michael Tkachev
"Conawapa11" <co******@hotmail.com> wrote in message
news:62**************************@posting.google.c om...
I'm having trouble figuring this problem out and every example out
there deals with simple objects within a custom collection. Take this
example:

public class ComplexClass
{
private int id;
private InnerClass anotherOne;

public int ID
{
get { return id; }
}
public InnerClass AnotherOne
{
get { return anotherOne; }
}
}

public class InnerClass
{
private int id;
private string name;

public int ID
{
get { return id; }
}
public string Name
{
get { return name; }
}
}

then I have a
public class ComplexCustomCollection : CollectionBase
that contains a list of ComplexClass objects.

Now in my Custom Control, I have a DataGrid that I want to bind to
this ComplexCustomCollection.

When creating columns, I have something like:

BoundColumn column = new BoundColumn();
column.DataField = "ID";
column.HeaderText = "ID #";
myGrid.Columns.Add(column);

column = new BoundColumn();
column.DataField = "AnotherOne.Name"; // just a guess
column.HeaderText = "Another Name";
myGrid.Columns.Add(column);

myGrid.DataSource = myComplexCustomCollection;
myGrid.DataBind();
Which, when ran results in:
A field or property with the name 'AnotherOne.Name' was not found on
the selected datasource.
How can I bind to that inner class's properties?
Any help would be much appreciated. Thanks in advance...

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
5
by: K | last post by:
I created a collection which is derived from ArrayList and implements IBindingList and ITypedList. Then I bound the DataSource of a data grid into the collection. It could show up the data but...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Just D | last post by:
Hi, If anybody needs to show some data retrieved from the database table, what method is more preferrable? 1. DataSet ds = ...; DataGrid.Data.Source.ds; DataGrid.Bind(); 2. Write a custom...
1
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a collection object, and each collection element...
4
by: nmosafi | last post by:
I have a datagrid that I am binding to a custom collection, and I am having problems with data binding in an ASP.NET datagrid (1.1 framework). As a simple example, imagine a class called...
0
by: Stephajn Craig | last post by:
I've built a customized collection class that has strongly typed objects in it. I have a collection class called LogEntryCollection with LogEntry objects in it. Each LogEntry object has certain...
1
by: viktor9990 | last post by:
I'm trying to bind a custom collection to an autogenerated datagrid without success. I'm getting this error: DataGrid with id 'DataGrid2' could not automatically generate any columns from the...
1
by: Suresh | last post by:
Using ASP.NET 1.1 ---------------------- I have a custom collection of object that I'm binding to a datagrid. Each of these objects have another collection inside them. I have a user control...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.