Listbox Databinding to array of simple objects fails

P

Paul

Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite a lot, but
none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country" objects via
a WebService. The Country class contains CountryID,TLDs and Name properties
each of which have a getter and setter (I found that properties without
setters are not serialised).

During debug I can see the datasource of my listbox and that it contains 13
items, each of which is a Country object, including the "Name" and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the setting of
the datatextfield I get the same error with CountryID) and neither has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country} System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country

Any help appreciated.

Paul
 
P

pauled

Hi,

They are public properties with a getter and setter for each.

Thanks

Paul said:
Are they really properties or just fields? Are they public?

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Paul said:
Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite a lot,
but none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country" objects
via a WebService. The Country class contains CountryID,TLDs and Name
properties each of which have a getter and setter (I found that properties
without setters are not serialised).

During debug I can see the datasource of my listbox and that it contains
13 items, each of which is a Country object, including the "Name" and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the setting of
the datatextfield I get the same error with CountryID) and neither has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl
{System.Web.UI.WebControls.ListBox} System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country}
System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country

Any help appreciated.

Paul
 
P

pauled

A small update.

If I construct an array of type Country I can create a list item
manually adding the members of the array as I itterrate through them.
The CountryID and Name values are available (even in the intelliscense)
and the list box appears correct.

So what does the the DataBind() method do differently to what I'm doing
manually for it to fail?

Cheers

Paul

Hi,

They are public properties with a getter and setter for each.

Thanks

Paul said:
Are they really properties or just fields? Are they public?

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Paul said:
Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite a lot,
but none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country" objects
via a WebService. The Country class contains CountryID,TLDs and Name
properties each of which have a getter and setter (I found that properties
without setters are not serialised).

During debug I can see the datasource of my listbox and that it contains
13 items, each of which is a Country object, including the "Name" and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the setting of
the datatextfield I get the same error with CountryID) and neither has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl
{System.Web.UI.WebControls.ListBox} System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country}
System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country

Any help appreciated.

Paul
 
K

Karl Seguin [MVP]

I still think something's wrong with your Country class. DataBind workds
fine against public, non-static/shared properties.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


A small update.

If I construct an array of type Country I can create a list item
manually adding the members of the array as I itterrate through them.
The CountryID and Name values are available (even in the intelliscense)
and the list box appears correct.

So what does the the DataBind() method do differently to what I'm doing
manually for it to fail?

Cheers

Paul

Hi,

They are public properties with a getter and setter for each.

Thanks

Paul said:
Are they really properties or just fields? Are they public?

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite a
lot,
but none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country"
objects
via a WebService. The Country class contains CountryID,TLDs and Name
properties each of which have a getter and setter (I found that
properties
without setters are not serialised).

During debug I can see the datasource of my listbox and that it
contains
13 items, each of which is a Country object, including the "Name" and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the
setting of
the datatextfield I get the same error with CountryID) and neither
has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl
{System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country}
System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country

Any help appreciated.

Paul
 
P

pauled

This is the code for my Country class, it's very simple.

namespace TLD.Manager
{

public class Country
{
public Country()
{}

private int _countryid = 0;

private string _name;

private TLD[] _tlds;


public int CountryID
{
get{return this._countryid;}
set{this._countryid = value;}
}

public string Name
{
get{return this._name;}
set{this._name = value;}
}

public TLD[] TLDs
{
get{return this._tlds;}
set{this._tlds = value;}
}

public static Country[] GetCountryNames()
{
SqlConnection con = new
SqlConnection(ConfigurationSettings.AppSettings["DBConn"]);
SqlCommand com = new SqlCommand("up_SelectCountryNames",con);
com.CommandType = CommandType.StoredProcedure;
ArrayList al = new ArrayList();
con.Open();
SqlDataReader dr = com.ExecuteReader();
while(dr.Read())
{
Country c = new Country();
c._countryid = Convert.ToInt32(dr["CountryID"]);
c._name = dr["Country"].ToString();
al.Add(c);
}
con.Close();
con.Dispose();
com.Dispose();
return (Country[])al.ToArray(typeof(Country));
}

}

My web service simply provides a web method that returns the result of
the GetCountryNames() method call.

Paul
I still think something's wrong with your Country class. DataBind workds
fine against public, non-static/shared properties.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


A small update.

If I construct an array of type Country I can create a list item
manually adding the members of the array as I itterrate through them.
The CountryID and Name values are available (even in the intelliscense)
and the list box appears correct.

So what does the the DataBind() method do differently to what I'm doing
manually for it to fail?

Cheers

Paul

Hi,

They are public properties with a getter and setter for each.

Thanks

Paul
Karl Seguin [MVP] wrote:

Are they really properties or just fields? Are they public?

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite a
lot,
but none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country"
objects
via a WebService. The Country class contains CountryID,TLDs and Name
properties each of which have a getter and setter (I found that
properties
without setters are not serialised).

During debug I can see the datasource of my listbox and that it
contains
13 items, each of which is a Country object, including the "Name" and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the
setting of
the datatextfield I get the same error with CountryID) and neither
has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl
{System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country}
System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country} RiskReport.TLDManager.Country

Any help appreciated.

Paul
 
K

Karl Seguin [MVP]

Yes, that does look normal...

The namespace in the error is RiskReport.TLDManager.Country and your class
namespace seems to be TLD.Manager I take it it's just a sample typo, but
wanted to point it out incase it leads to anything..

I can't see anything else out of the ordinary...I still think it's something
silly staring both of us in the eyes...

If you want, you can zip up a sample project and send it to me, I'm more
than happy to take a closer look @ it.

Karl
--
http://www.openmymind.net/
http://www.codebetter.com/


This is the code for my Country class, it's very simple.

namespace TLD.Manager
{

public class Country
{
public Country()
{}

private int _countryid = 0;

private string _name;

private TLD[] _tlds;


public int CountryID
{
get{return this._countryid;}
set{this._countryid = value;}
}

public string Name
{
get{return this._name;}
set{this._name = value;}
}

public TLD[] TLDs
{
get{return this._tlds;}
set{this._tlds = value;}
}

public static Country[] GetCountryNames()
{
SqlConnection con = new
SqlConnection(ConfigurationSettings.AppSettings["DBConn"]);
SqlCommand com = new SqlCommand("up_SelectCountryNames",con);
com.CommandType = CommandType.StoredProcedure;
ArrayList al = new ArrayList();
con.Open();
SqlDataReader dr = com.ExecuteReader();
while(dr.Read())
{
Country c = new Country();
c._countryid = Convert.ToInt32(dr["CountryID"]);
c._name = dr["Country"].ToString();
al.Add(c);
}
con.Close();
con.Dispose();
com.Dispose();
return (Country[])al.ToArray(typeof(Country));
}

}

My web service simply provides a web method that returns the result of
the GetCountryNames() method call.

Paul
I still think something's wrong with your Country class. DataBind workds
fine against public, non-static/shared properties.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


A small update.

If I construct an array of type Country I can create a list item
manually adding the members of the array as I itterrate through them.
The CountryID and Name values are available (even in the intelliscense)
and the list box appears correct.

So what does the the DataBind() method do differently to what I'm doing
manually for it to fail?

Cheers

Paul

(e-mail address removed) wrote:
Hi,

They are public properties with a getter and setter for each.

Thanks

Paul
Karl Seguin [MVP] wrote:

Are they really properties or just fields? Are they public?

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/


Hi All,

Framework 1.1 listbox control unable to DataBind

I've been googling for an answer to this query that appears quite
a
lot,
but none, it seem, answers my problem directly.

I am populating a listbox with an array of very simple "Country"
objects
via a WebService. The Country class contains CountryID,TLDs and
Name
properties each of which have a getter and setter (I found that
properties
without setters are not serialised).

During debug I can see the datasource of my listbox and that it
contains
13 items, each of which is a Country object, including the "Name"
and
"CountryID" properties and these have values.

However on Binding the lisbox to the datasource I get the error

"DataBinder.Eval: 'RiskReport.TLDManager.Country' does not contain
a
property with the name Name. "

Name is not miss-spelt nor is CountryID (If commenting out the
setting of
the datatextfield I get the same error with CountryID) and neither
has
leading or trailing spaces etc


Bidning code

this.lbCountries.DataSource = api.GetCountries();
this.lbCountries.DataTextField = "Name";
this.lbCountries.DataValueField = "CountryID";
this.lbCountries.DataBind();

Copy of Auto's when viewing the DataSource property of the listbox
in
question.


-- lbCountries {System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListBox
- System.Web.UI.WebControls.ListControl
{System.Web.UI.WebControls.ListBox}
System.Web.UI.WebControls.ListControl
- DataSource {System.Array} System.Object
- [0] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
System.Object {RiskReport.TLDManager.Country}
System.Object
CountryID 11 int
Name "Australia" string
TLDs <undefined value> RiskReport.TLDManager.TLD[]
+ [1] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [2] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [3] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [4] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [5] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [6] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [7] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [8] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [9] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [10] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [11] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country
+ [12] {RiskReport.TLDManager.Country}
RiskReport.TLDManager.Country

Any help appreciated.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top