Need comments on construction of pages getting their data from custom classes

Discussion in 'ASP .Net Web Controls' started by Evert Wiesenekker, Mar 25, 2006.

  1. When I started learning ASP.NET two years ago I created my pages in a
    visually oriented way, eg by dragging and dropping controls on the
    page. I mainly used DataGrid's binding their data to custom made SQL
    Server stored procedures. To get more binding control I later developed
    template columns for my DataGrid's. This works very well.

    Now I just started a very small project, which is too small to use SQL
    Server for. For this project I decided to use another approach:
    designing custom classes (the OO-way). So I designed for example a
    Person class, an Address clas ect. For storage I use XML serializtion.
    This works amazingly simple, even my complex classes, which contain
    other collections of classes, serialize perfectly! So I was very happy
    with my Object model and switched to the toolbar and found out the
    binding to Visual Controls seems not very clear to me. How do I bind in
    a simple manner my custom classes to Visual controls. It seems to me me
    I cannot do a simple databind, because the ouput needs to be generated
    based on the value of some poperties. So for example suppose I have a
    Shop which has a collection of Products, I only want the Repeater
    control (or whatever visual control) to display its products which are
    available (eg some property of a product instance has a DateTime
    greater than the current date).

    Now I saw a solution from a collegue of mine. He uses the Table object
    and dynamically creates the table: he foreaches over the custom
    collection and for every instance he creates a TableRow with the
    apporiate TableCells. I found it a very simple solution giving a lot of
    flexibility (and code..). When I used the DataGrid's OnDataBinding
    event in combination with the FindControl method a little awkward.

    Now I am using his solution and want to know if this is the way to go
    for custom classes. Because I have the eerie feeling this can be done
    in a more advanced way.

    Thanks for any comments!

    Evert Wiesenekker

    By the way I am using now VS 2005
    Evert Wiesenekker, Mar 25, 2006
    1. Advertisements

  2. I got a little further today:

    I decided to give my base class a method RetrieveProducts which returns
    a DataTable object suitable (formatted) for my presentation layer. This
    DataTable I can easily bind to a Repeater. Now I get the feeling I got
    back where I started, using DataTables again...
    Evert Wiesenekker, Mar 25, 2006
    1. Advertisements

  3. Evert Wiesenekker



    ObjectDataSource(ODS) that is available in ASP.Net 2.0 (VS 2005) would
    work nicely with your data control (DataGrid) and strongly typed
    business objects (Person etc.) that you've already created.
    So you can have an ODS called PersonDataSource that works with your
    Person class and your data source can bind to the PersonDataSource to
    work with your Person class.

    There are lots of examples on how to use the ObjectDataSource on the

    And while you are investigating the ObjectDataSource, look at using the
    new grid data control called GridView rather than using DataGrid.
    GridView has supports sorting, paging, update, delete, multiple keys
    and more events with no or minimal coding. Of cause you can still
    customise the GridView with code if it does not do exactly what you
    want. For example - GridView does not, by default, support in-place
    data insertion therefore you'll need to code in that support if that's
    what you require.

    Good Luck.
    , Mar 25, 2006
  4. Thanks you for your reply, I missed that control. Looks interesting!

    Evert Wiesenekker, Mar 26, 2006
    1. Advertisements

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 T. Hatton

    Recursive construction of derived classes.

    Steven T. Hatton, May 15, 2005, in forum: C++
    Steven T. Hatton
    May 15, 2005
  2. Replies:
  3. Monk
    Michael Wojcik
    Apr 20, 2005
  4. Ook
  5. Replies:
  6. James Kanze
    James Kanze
    Oct 9, 2008
  7. coltrane
    James Kanze
    Aug 25, 2010
  8. Replies:
    Dr John Stockton
    Jun 3, 2006