Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

ASP DataRepeater control

I have a rather strange question: why do we need the DataRepeater?  Granted, it's more flexible than the DataGrid as it gives you fineer control over what's displayed, but it doesn't seem any easier to use than just good old hand-made table that you build while going through the recordset (pardon, DataReader).
I don't think that

<td><%# Container.DataItem("LastName") &
            ", " & Container.DataItem("FirstName") %>

is any easier or more intuitive than

<td><% =dr("LastName")  & ", " & dr("FirstName") %>

- and the latter certainly isn't any less flexible.

So, what's the point ?  Or am I missing something big time ?

Friday, February 21, 2003

If you were doing it the latter way, you would have to put a while loop in your HTML code to loop through the records. The DataRepeater keeps that out, allowing for a cleaner seperation of the layers.

Sunday, February 23, 2003

Yes, of course, that I understand, but I can't believe it's
the only benefit. By separation of layers, you probably  mean presentation and business logic (VB and HTML), but you'd have to intermix Vb and HTML anyway if you want
to do any sort of custom display - and if you don't, you'll just use DataGrid...

Monday, February 24, 2003

Actually, the best idea for custom display in ASP.NET is NOT to put code in the aspx file - it's to write a web control. Encapsulate your custom display in a new tag. Keeps logic and layout separated, and it makes it much easier to reuse whatever you cooked up in other pages.

Chris Tavares
Tuesday, February 25, 2003

For one, DataBinding.

If you use <%= %>, it gets evaluated EVERY time the page gets processed.  DataBound controls like the DataList, Grid, et al only get processed when you call DataBind.

Secondly, abstraction.  Manually generating your own table leaves you with a generated table.  Using a DataGrid or List etc. leaves you with an Object that you can access programmatically.  You can get the Items.Count.  You can assign special templates for the SelectedItem and EditItem.  There's really a lot of added functionality there.

In the end, it just generates HTML, so there's nothing you cand do with ASP.NET that you couldnt' do the old fashioned way.  You just get all the nice features with a lot less work.  If you were just doing a table or a list, then it's not so obvious, but if you want things like paging and sorting, that was basically a custom implementation in classic ASP.

Richard Ponton
Wednesday, March 05, 2003

*  Recent Topics

*  Fog Creek Home