Tutorial : Repeater Control in ASP.NET
Published on 19 December 12
2738
0
During the development of web application with ASP.NET, you may have to come across a situation in which you need to display a section in your left bar or right bar containing a list of certain items. Data of these items must be coming from the database. For example, if you are developing a car selling website and you need to show 4 cars which have been placed for sale most recently. This situation requires the use of a specific ASP.NET control referred to as Repeater control.
Rather than having to run a loop to display database values, Repeater provides a very easy to use method to display database items in a list.
Here, an example is shown which has to display a list of most recent cars placed for sale, along with the image of the cars.
Step 1)The first thing that you need to do is to define the data source of Repeater control. We will use ObjectDataSource as the source of this control. You can create an ObjectDataSource control by dragging it from the Data category of the Toolbox.
![Tutorial : Repeater Control in ASP.NET - Image 1](http://programming2learn.com/wp-content/uploads/2012/11/objectdata.png)
(ObjectDataSource Box)
Step 2) Drag the ObjectDataSource from the toolbox, click on the arrow symbol visible on the right side of control and click on Configure data source to define the source of data.
![Tutorial : Repeater Control in ASP.NET - Image 2](http://programming2learn.com/wp-content/uploads/2012/11/objecttasks-300x96.png)
(Toolbox)
Step 3) This will take you to a wizard to define data source properties. At the completion of this process following code will be generated for the newly created ObjectSource control.
Step 4) After defining the Data Source object you must create the Repeater control in a similar way, by dragging it from the Data category of the Toolbox.
![Tutorial : Repeater Control in ASP.NET - Image 3](http://programming2learn.com/wp-content/uploads/2012/11/toolbox2.png)
(Toolbox)
Step 5) Then set the Datasource property of the Repeater object to the newly created ObjectSource control. Following piece of code reflects the settings of Repeater object.
ItemTemplate attribute refers to the settings of an individual record. Here we have to display the car image and car title and clicking on any of these must take the user to the description of related car. Both of these are encapsulated into HyperLink control. ItemAddress is a function defined in the vb file. It receives car id and returns the web page on which information about the selected car may be available.
Protected Function itemAddress(ByVal val As Integer) As String Return "carDetails.aspx?CarID=" & val End Function Then there is an image control of ASP.NET. ImageUrl property of Image control is obtained with the help of imgAddress() function defined in the vb file. And then car title is displayed. The Eval function having the input of a field returns the relevant ObjectSource data.
The resultant repeater control may look like this on a web page.
![Tutorial : Repeater Control in ASP.NET - Image 4](http://programming2learn.com/wp-content/uploads/2012/11/repeater-control.png)
(Repeater Control)
-----
Learn more about programming here.
This review is listed under
Development & Implementations
and Data & Information Management
Community
Related Posts:
Post a Comment