Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid Binding to Complex Custom Collection

Reply
Thread Tools

DataGrid Binding to Complex Custom Collection

 
 
Conawapa11
Guest
Posts: n/a
 
      11-14-2003
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...
 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      11-14-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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...



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
trouble binding a datagrid to a custom collection =?Utf-8?B?dmlrdG9yOTk5MA==?= ASP .Net 1 03-16-2006 09:56 PM
Update Custom Collection that is bound to DataGrid made up of Custom COlumns Terry Holland ASP .Net Datagrid Control 9 10-28-2005 06:20 AM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
Help: Data Binding to Custom Collection Shrage Smilowitz ASP .Net 2 10-31-2003 12:27 AM



Advertisments