In this article I will explain with an example, how to populate (bind) Repeater control using SqlDataSource in ASP.Net.
Here I am making use of Microsoft’s Northwind Database. The download and install instructions are provided in the following article.
HTML Markup
The following HTML Markup consists of an ASP.Net Repeater control and ASP.Net SqlDataSource control.
The SqlDataSource control is set with the following properties.
1. ConnectionString – Name of the Connection String setting in the Web.Config file.
2. SelectCommand – The Select statement to fetch the records from the Customers table of the Northwind database.
The ID of the SqlDataSource control is set as DataSourceID of the Repeater control.
<asp:Repeater ID="rptCustomers" runat="server" DataSourceID="SqlDataSource1">
        <table cellspacing="0" rules="all" border="1">
                <th scope="col" style="width: 80px">
                    Customer Id
                <th scope="col" style="width: 120px">
                    Customer Name
                <th scope="col" style="width: 100px">
                <asp:Label ID="lblCustomerId" runat="server" Text='<%# Eval("CustomerId") %>'/>
                <asp:Label ID="lblContactName" runat="server" Text='<%# Eval("ContactName") %>'/>
                <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
    SelectCommand="SELECT TOP 10 * FROM Customers"></asp:SqlDataSource>
Populate (Bind) Repeater control using SqlDataSource in ASP.Net