Everybody Read this and participate. How to bind custom object collection to a datagrid.?

Discussion in 'ASP .Net' started by Luis Esteban Valencia, Jul 1, 2005.

  1. Please everybody participate in this question.

    Hello my applicacion has many layers and classes and I think its well
    structured. PLease let me know if you disagree and why.
    1. I have the user Interface (webforms)
    2. I have a class Called Customer Class (it only has private fields,
    properties). Those properties connecto a Class called
    CustomerDALC (Customer Data Access Logic Component). this one must be the
    only responsible to access data. the acess of the data must be transparent
    to the customerclass.
    3. This last class is the one that actually retrieves or sets the
    information from the database.

    So here is the code.

    public class Customer
    {
    // Private fields, to hold the state of the Product entity
    private int customerId;
    private string firstname;
    private string lastname;

    CustomerDALC objcustomerDalc;

    // Public properties, to expose the state of the entity
    public int getName
    {
    get { return objcustomerDalc.getFirstName(customerId); }
    set { objCustomerDALC.setFistName(value, customerId); }

    }

    CustomerClass.Cs

    public class CustomerDALC
    {
    private string conn_string;

    public CustomerDALC()
    {
    // Acquire the connection string from a secure or encrypted location
    // and assign to conn_string
    }
    public int getName(int id)
    {
    return sqlhelper.executereader("blablabla"); ///Resuming of course
    }
    public void setName(string name, int id)
    {
    return sqlhelper.executereader("blablabla"); ///Resuming of course
    }
    }


    Suppose that in my webform I want to retrieve all the customers and bind to
    a datagrid? what is the best way to do it?
    Create an array of CustomerObjects? or create a dataset? where would I put
    that dataset.




    I took the code from this page
    http://msdn.microsoft.com/practices/ArchDes/default.aspx?pull=/library/en-us/dnbda/html/boagag.asp

    If you have other techniques to program with layers and objects and passing
    info between layers please let me know. I am trying to modelate a generic
    way to make this but I havent done it before.
    Luis Esteban Valencia, Jul 1, 2005
    #1
    1. Advertising

  2. Luis Esteban Valencia

    Joe Fallon Guest

    Rocky Lhotka's CSLA Framework is very useful.
    http://www.lhotka.net/ArticleIndex.aspx?area=CSLA .NET

    I use it to create custom Business Objects including Editable collections of
    Customer objects and more lightweight Read Only Collections of CustomerInfo
    objects. I use the ROCs to bind to grids.

    You can choose to keep the ROC in session for postbacks (and remove it when
    you leav the page)
    or hit the DB each time to retireve it. Depends on your needs.
    --
    Joe Fallon



    "Luis Esteban Valencia" <> wrote in message
    news:uu$...
    > Please everybody participate in this question.
    >
    > Hello my applicacion has many layers and classes and I think its well
    > structured. PLease let me know if you disagree and why.
    > 1. I have the user Interface (webforms)
    > 2. I have a class Called Customer Class (it only has private fields,
    > properties). Those properties connecto a Class called
    > CustomerDALC (Customer Data Access Logic Component). this one must be the
    > only responsible to access data. the acess of the data must be transparent
    > to the customerclass.
    > 3. This last class is the one that actually retrieves or sets the
    > information from the database.
    >
    > So here is the code.
    >
    > public class Customer
    > {
    > // Private fields, to hold the state of the Product entity
    > private int customerId;
    > private string firstname;
    > private string lastname;
    >
    > CustomerDALC objcustomerDalc;
    >
    > // Public properties, to expose the state of the entity
    > public int getName
    > {
    > get { return objcustomerDalc.getFirstName(customerId); }
    > set { objCustomerDALC.setFistName(value, customerId); }
    >
    > }
    >
    > CustomerClass.Cs
    >
    > public class CustomerDALC
    > {
    > private string conn_string;
    >
    > public CustomerDALC()
    > {
    > // Acquire the connection string from a secure or encrypted location
    > // and assign to conn_string
    > }
    > public int getName(int id)
    > {
    > return sqlhelper.executereader("blablabla"); ///Resuming of course
    > }
    > public void setName(string name, int id)
    > {
    > return sqlhelper.executereader("blablabla"); ///Resuming of course
    > }
    > }
    >
    >
    > Suppose that in my webform I want to retrieve all the customers and bind
    > to
    > a datagrid? what is the best way to do it?
    > Create an array of CustomerObjects? or create a dataset? where would I put
    > that dataset.
    >
    >
    >
    >
    > I took the code from this page
    > http://msdn.microsoft.com/practices/ArchDes/default.aspx?pull=/library/en-us/dnbda/html/boagag.asp
    >
    > If you have other techniques to program with layers and objects and
    > passing
    > info between layers please let me know. I am trying to modelate a generic
    > way to make this but I havent done it before.
    >
    >
    Joe Fallon, Jul 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Baggs
    Replies:
    5
    Views:
    43,322
    Steven Baggs
    Oct 18, 2005
  2. Robert Hathaway
    Replies:
    0
    Views:
    417
    Robert Hathaway
    Jul 29, 2003
  3. Robert Hathaway
    Replies:
    0
    Views:
    417
    Robert Hathaway
    Jul 29, 2003
  4. Robert Hathaway
    Replies:
    1
    Views:
    456
    Robert J Hathaway III
    Jul 29, 2003
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    958
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page