Working with Data in ASP.NET 2.0 Displaying Data with the DataList and Repeater Controls
In all of the examples throughout the past 28 tutorials, if we needed to display multiple records from a data source we turned to the GridView control. The GridView renders a row for each record in the data source, displaying the record’s data fields in columns. While the GridView makes it a snap to display, page through, sort, edit, and delete data, its appearance is a bit boxy. Moreover, the markup responsible for the GridView’s structure is fixed - it includes an HTML with a table row () for each record and a table cell () for each field. To provide a greater degree of customization in the appearance and rendered markup when displaying multiple records, ASP.NET 2.0 offers the DataList and Repeater controls (both of which were also available in ASP.NET version 1.x). The DataList and Repeater controls render their content using templates rather than BoundFields, CheckBoxFields, ButtonFields, and so on. Like the GridView, the DataList renders as an HTML , but allows for multiple data source records to be displayed per table row. The Repeater, on the other hand, renders no additional markup than what you explicitly specify, and is an ideal candidate when you need precise control over the markup emitted.
Step 1: Adding the DataList and Repeater Tutorial Web Pages
Before we start this tutorial, let’s first take a moment to add the ASP.NET pages we’ll need for this tutorial and the next few tutorials dealing with displaying data using the DataList and Repeater. Start by creating a new folder in the project named DataListRepeaterBasics. Next, add the following five ASP.NET pages to this folder, having all of them configured to use the master page Site.master:
- Default.aspx
- Basics.aspx
- Formatting.aspx
- RepeatColumnAndDirection.aspx
- NestedControls.aspx
Open the Default.aspx page and drag the SectionLevelTutorialListing.ascx User Control from the UserControls folder onto the Design surface. This User Control, which we created in the Master Pages and Site Navigation tutorial, enumerates the site map and displays the tutorials from the current section in a bulleted list.
…
Step 2: Displaying Product Information with the DataList
Similar to the FormView, the DataList control’s rendered output depends upon templates rather than BoundFields, CheckBoxFields, and so on. Unlike the FormView, the DataList is designed to display a set of records rather than a solitary one. Let’s begin this tutorial with a look at binding product information to a DataList. Start by opening the Basics.aspx page in the DataListRepeaterBasics folder. Next, drag a DataList from the Toolbox onto the Designer. As Figure 4 illustrates, before specifying the DataList’s templates, the Designer displays it as a gray box.
…
Website: static.asp.net | Filesize: 1090kb
No of Page(s): 19
Click here to download Working with Data in ASP.NET 2.0 Displaying Data with the DataList and Repeater Controls.
Related Tutorial
Tags: .NET, data binding, web control
Comments
Leave a Reply