Discussion:
Business objects with no properties and data binding
Alex Ivanoff
2007-03-01 21:20:21 UTC
Permalink
Is it possible to data bind a web control (DropDownList) to a list of
business objects which do not have properties but accessor methods instead:

public class State
{
private String _abbr;
private String _name;

public String GetAbbr()
{
return this._abbr;
}

public String GetName()
{
return this._name;
}
}

Thank you,
Alex

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Efran Cobisi
2007-03-02 08:19:39 UTC
Permalink
Hi,

Afaik this is not possible, because bound values are gathered using the
System.Web.UI.DataBinder:GetDataItem() method, which expects public
properties.
You could, however, write a proxy for your object, which could abstract
the logic required to access data in your object, allowing to retrieve
using public properties.

HTH,

Efran Cobisi
http://www.cobisi.com

Alex Ivanoff wrote:
> Is it possible to data bind a web control (DropDownList) to a list of
> business objects which do not have properties but accessor methods instead:
>
> public class State
> {
> private String _abbr;
> private String _name;
>
> public String GetAbbr()
> {
> return this._abbr;
> }
>
> public String GetName()
> {
> return this._name;
> }
> }
>
> Thank you,
> Alex
>
> ===================================
> This list is hosted by DevelopMentor® http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Ivanoff, Alex
2007-03-02 14:52:34 UTC
Permalink
Paul van Brenk
2007-03-02 09:21:29 UTC
Permalink
Ivanoff, Alex
2007-03-02 14:56:24 UTC
Permalink
Pardee, Roy
2007-03-02 18:01:27 UTC
Permalink
Alex Ivanoff
2007-03-02 20:32:16 UTC
Permalink
Pardee, Roy
2007-03-02 20:54:22 UTC
Permalink
Ivanoff, Alex
2007-03-03 17:19:34 UTC
Permalink
Marc Brooks
2007-03-04 05:12:00 UTC
Permalink
> Getters usually do not change the state of the object.

But they can do some significant (delayed) work to get the correct value.

> Properties are not encapsulation. They are syntactical sugar of a language.

Properties are the public-level abstraction the to the fields of an
object, they are most definately useful to encapsulate some attributes
of the object. You don't like them, but you are fighting against the
"current" of the CLR databinding merely because you don't need the
sugar.... not for any real danger in using them.

--
"I am Dyslexic of Borg. Resistors are fertile. Prepare to have your
ass laminated." -- Dan Nitschke

Marc C. Brooks
http://musingmarc.blogspot.com

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
Ivanoff, Alex
2007-03-04 16:01:03 UTC
Permalink
Continue reading on narkive:
Loading...