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

E

Evert Wiesenekker

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
 
E

Evert Wiesenekker

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...
 
C

CaffieneRush

Hi,

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.
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.objectdatasource(VS.80).aspx

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

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.
 
E

Evert Wiesenekker

Thanks you for your reply, I missed that control. Looks interesting!

Evert
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top