How to Use a Repeater Control in ASP.NET
See more tutorials in Controls. This post has Comments Off on How to Use a Repeater Control in ASP.NET.
In this tutorial we will learn how to create and use repeaters in ASP.NET. Repeaters can be useful when dealing with information in SQL Databases, especially if it is a dynamic number of information that you are grabbing. GridViews can be used as an alternative to Repeaters, and they generally have a more formatted table like style.
Step 1. Setup the Project and Create the Repeater
1. Create a new Project in Visual Web Developer
2. Create a new Web From named “Default.aspx”
3. Create a new SQL Database and name it “Repeater.mdf”
4. Inside that Database create a Table called “Repeater” with the Columns ID(Primary Key, Identity), and Name(varchar(50))
5. Fill the Table out with some sample Data by right clicking it and selecting Show Table Data
6. Now go onto the form and drag an SQL data source object onto the form
7. Setup the SQL data source to connect to the Database and Table we just created by clicking on the Smart Tag and selecting Configure DataSource
Step 2. Linking the Repeater and the Database
1. Drag a Repeater Control from the Data Section of the Toolbar onto the Form
2. Click on the Smart Tag and select the Data Source we just created (“SqlDataSource1″ for me)
3. Unlike a GridView the Repeater requires a few extra steps to setup. Inside the
<%# Eval(“ID”) %> <%# Eval(“Name”) %><br />
4. We can now run the project and view how the Repeater displays our Data.
In this tutorial we learned how to create and setup a Repeater Control in ASP.NET. The repeater Control is very useful and dynamic in how it is setup. In ASP.NET there is another Control Called the GridView Control that can achieve similar results to the Repeater in a more uniform table like style (link to be added).