ASP.Net C# Repeater Databinding using DataSource
ASP.Net Repeater Databound Control Databinding feature displays the data items retrieved from any DataSource in the specified repeated list layout. Here we will discuss the ASP.Net C# code to connect with SQL Server Database and Repeater control databinding using its DataSource object that gets or sets the data provided by the data source for populating the repeated list items. In the previous article about ASP.Net Repeater Control we discussed about 5 types of templates that can be used to customize the layout of Repeater DataBound Control. ItemTemplate field is a required template to display the data retrieved from the DataSource. You can specify the heading for data list items in the HeaderTemplate.
Repeater Examples:
You can see the live samples and examples of Repeater Control from the following links:
In this Repeater Control Tutorial we will use Northwind SQL database to bind the data with Repeater Control. Define the Following connectionstring in the web.config file’s ConnectionStrings section:
<add
name="ConStr"
connectionString="Server=localhost; Database=northwind; uid=sa; pwd=;"
providerName="System.Data.SqlClient">
</add>
HTML Code for Repeater Control and DataBinder.Eval Function
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<h4>
Emplyee Names</h4>
</HeaderTemplate>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"FirstName") %>
<%#DataBinder.Eval(Container.DataItem,"LastName") %>
<br />
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
</asp:Repeater>
DataBinder class provides the Eval function that accepts two parameters. First parameter value as a reference against the DataItem object using Container variable of as RepeaterItem that is to be evaluated. Second parameter is a string type expression that passes the name of Data Field retrieved from the DataSource.
ASP.Net C# Code for Repeater Databinding using DataSource
// string variable to store the connection string
// defined in connectionstrings section of web.config file.
string connStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
// object created for SqlConnection Class.
SqlConnection mySQLconnection = new SqlConnection(connStr);
// if condition that can be used to check the sql connection
// whether it is already open or not.
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
}
// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from employees", mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
// Repeater Control Databinding using Datasource
Repeater1.DataSource = myDataSet;
Repeater1.DataBind();
// if condition that can be used to check the sql connection
// if it is open then close it.
if (mySQLconnection.State == ConnectionState.Open)
{
mySQLconnection.Close();
}
Output result of ASP.Net repeater control will show you that Repeater control does not render extra HTML tags like <table> HTML tag in DataList or GridView Databound controls of ASP.Net
Output:
Get the output for above discussed code from the following link:
Continue to next tutorial: ASP.Net Repeater dynamically using C# code to learn how to generate the Repeater control programmatically.

I want to know the paging in Repeator control in asp.net using C#
regards veena