|
Choose the Right Tab Control
Select the ASP.NET list control that matches your app's needs.
by Doug Thews
Posted July 2, 2004
Technology Toolbox: VB.NET, SQL Server 2000, ASP.NET, Visual Studio .NET 2003
ASP.NET supports three types of list controls that you can use to display data in a tabular format: Repeater, DataList, and DataGrid. Each has specific strengths and weaknesses that you should take into consideration before selecting one for your application. In this article, I'll cover the controls' features and when it's best to use each one. For a preview of what ASP.NET 2.0 has to offer, see the sidebar, "What's New for Tabular List Controls in ASP.NET 2.0?" Download the sample Web pages described in this article here.
The Repeater control is the simplest of the ASP.NET list controls. It's used traditionally to display the data from a data source one item after the other (although you can customize it to view information in the classic rows and columns view). It provides a read-only view, and it doesn't support inline editing, paging, or sorting.
The Repeater has no default appearance, even when it's bound to a default data source. It requires a data source and at least one of the supported template tags:
<HeaderTemplate>
<ItemTemplate>
<AlternatingItemTemplate>
<FooterTemplate>
ASP.NET applies the formatting defined inside these tags to the items of that type. Consider how you use the Repeater format templates to create a table view of the SQL Server Authors database table (see Listing 1). Notice that the HTML Table definition begins inside the <HeaderTemplate> and concludes inside the <FooterTemplate>.
You can associate a server-side event handler to provide additional functionality. For example, if you supply an event handler for the Repeater's OnItemCommand event, your event handler fires whenever a user clicks on a child control within the Repeater:
<asp:repeater id="pubsRepeater"
OnItemCommand="myItemEventHandler"
runat="server">
Keep in mind that all child control events inside the Repeater "bubble up" to this event handler, so you'll need to provide logic within it to determine what was clicked on.
When you look at the output of the Repeater for the Authors example, you can see that the Repeater is the simplest of all tabular list controls (see Figure 1). You should use it when you want to display data from a repeatable data source in a simple, read-only format. You don't need to support in-line editing, and you don't need event handling capabilities for child controls within the table.
Back to top
|