Friday, March 30, 2007

ASP.NET Repeater vs. ASP.NET DataGrid

Personally, I find myself always using the Repeater or DataList as opposed to the DataGrid for all my custom reporting needs. And unless I need the horizontal display capabilities of the DataList, I always use the Repeater. Here are my problems with the DataGrid.

First, the DataGrid's built-in paging capabilities are horrible in terms of performance. It's built-in paging grabs all the rows from the database with each call and then only displays the necessary records. For any real-world application, you will need to turn off the built-in paging and create your own custom paging.

Second, it is near impossible to make the DataGrid look really good as it doesn't work with CSS nearly as well as the repeater. I find the problem is that the ASP.NET DataGrid applies its itemstyle and alternating itemstyles to the rows () as opposed to the cells ().

Third, the ASP.NET DataGrid requires the ViewState for its sorting capabilities. So, unless you want all the viewstate data to decrease the performance of your application, you will have to turn off its built-in sorting and create your own sorting methodology.

Unless you need the inline editing or edititemstyle and selecteditemstyle, which I don't use that often, forget the ASP.NET DataGrid. You will end up having to build our own sorting and paging mechanisms, so you might as well enjoy the flexibility of the ASP.NET Repeater.

No comments: