Monday, 1 February 2010

GridView or Repeater?

What is the difference between GridView and Repeater? This is one of the most common questions that beginners ask when they are trying to get familiar with data bound controls. Both of these controls have their own using context and I try to explain when one should use GridView and when it is okay to use Repeater.

As first thing I want to say that GridView is more complex and powerful control that offers much more functionality than Repeater. Repeater has better performance because it is not so complex and doesn't offer so rich functionality.

Repeater

Repeater is okay if you need to show data from some data source. It offers the basic rendering options: header, item, alternating item, separator and footer. It is really up to developer how to fill these templates. By example, it is easy to use Repeater to show read-only lists using templated elements.

Repeater is faster because it offers only basic data bound control rendering functionalities. If you want to show data and you don't need any complex features described below then repeater is the right choice.

GridView

GridView is rendered as table with columns and it is created to show data and let users to manipulate it. GridView offers powerful built-in features like:

* events for sorting data when user clicks on column heading,
* row selection,
* row operations like adding, editing and deleting,
* paging,
* command columns and events to handle the commands.

GridView is excellent choice if there is a need to show tabular data and also provide users with features described above.

No comments:

Post a Comment