The SqlDataSource control is listed under Data category in the Toolbox. First step is to drag this control on to the Design surface of form (it can also be dragged into the Source of a Form). There will be no visual rendering of SqlDataSource control in the Design pane of the form. However, you can see this control listed in the Properties box for that form.
For example, you will see something like the following:
SqlDataSource1 System.Web.UI.WebControls.SqlDataSource
If you choose the above control in the Property box, you can see that control shown at the bottom strip bar of the Design window. From the Source pane, however, you can see the complete declaration of the SqlDataSource control, like the following:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
To make the above control get data from the database, you need to set the following properties:
Property: ConnectionString
This is how the database is accessed. You can type in the full string or select the connection string from your config file (shown in the dropdown for this property). An example string:
ConnectionString="Data Source=mydb;Initial Catalog=mycat;Persist Security Info=True;User ID=uid;Password=pword"
If you chose a connection string from the config file, it will be something like:
ConnectionString="<%$ ConnectionStrings:mydbconnstring %>"
Property: SelectCommand
In this case we are getting data from the database. So we need to set up a SELECT query.
For example: SelectCommand="SELECT Name, Address FROM Persons"
Property: DataSourceMode
Two modes are available to set the behavior this data source. Do you want just a read-only listing of the records it obtained from the database OR Do you want the data to be editable as well? For read-only, choose DataReader; and for read-write, choose DataSet. Since we just want to display data in this case, choose DataReader.
For example: DataSourceMode="DataReader"
That is it! Your SqlDataSource will get the data from the database when you want it. Your SqlDataSource declaration will look something like this:
<asp:SqlDataSource ID="sdsCustomer" runat="server"
ConnectionString="Data Source=mydb;Initial Catalog=mycat;Persist Security Info=True;User ID=uid;Password=pword"
DataSourceMode="DataReader" ProviderName="System.Data.SqlClient"
SelectCommand="SELECT Name, Address FROM Persons">
</asp:SqlDataSource>
Now attaching it to Repeater is as simple as setting the DataSourceID:
<asp:Repeater ID="rpt1" runat="server"
DataMember="DefaultView" DataSourceID="sdsCustomer" OnItemCommand="...">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate></ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>