A Repeater is a Data-bound control. Data-bound controls are container controls. It creates a link between the Data Source and the presentation UI to display the data. The repeater control is used to display a repeated list of items.
The main use of Repeater Control is for displaying a repeated list of items bound to the control. A Repeater Control is faster and lightweight for displaying data compared to a GridView or DataGrid. With the Repeater control we can display data in a custom format. The main drawback of a Repeater Control is that it doesn't support paging and sorting.
The Repeater Control has the following types of template fields,
- Item Template
- AlternatingItem Template
- Header Template
- Footer Template
- Separator Template
Write connection code and select command in code bihaind file like:
- protected void Page_Load(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection("Data Source=MCNDESKTOP34;Initial Catalog=yatendra;Persist Security Info=True;User ID=sa;
- Password = Password$2 ");
- SqlDataAdapter sda = new SqlDataAdapter("select * from Student_Details1", con); DataTable dt = new DataTable(); sda.Fill(dt); Repeater1.DataSource = dt; Repeater1.DataBind();
- }
Now use Repeater control object in .aspx file like:
- <asp:Repeater ID="Repeater1" runat="server">
- <ItemTemplate>
- <div>
- <table>
- <tr>
- <th>Student
- <%#Eval("S_ID")%>
- </th>
- </tr>
- <tr>
- <td>Student Name</td>
- <td>
- <%#Eval("Student_Name")%>
- </td>
- </tr>
- <tr>
- <td>Registration Number</td>
- <td>
- <%#Eval("Register_No")%>
- </td>
- </tr>
- <tr>
- <td>Date Of Birth</td>
- <td>
- <%#Eval("D_O_B")%>
- </td>
- </tr>
- <tr>
- <td>Date Of Examination</td>
- <td>
- <%#Eval("D_O_E")%>
- </td>
- </tr>
- <tr>
- <td>Department</td>
- <td>
- <%#Eval("Department")%>
- </td>
- </tr>
- </table>
- </div>
- </ItemTemplate>
- </asp:Repeater>
When you run this page the output will look like: