in Education by
How to use repeater control in ASP.NET?

1 Answer

0 votes
by

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:

  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.     SqlConnection con = new SqlConnection("Data Source=MCNDESKTOP34;Initial Catalog=yatendra;Persist Security Info=True;User ID=sa;  
  4.         Password = Password$2 ");   
  5.         SqlDataAdapter sda = new SqlDataAdapter("select * from Student_Details1", con); DataTable dt = new DataTable(); sda.Fill(dt); Repeater1.DataSource = dt; Repeater1.DataBind();  
  6. }  

Now use Repeater control object in .aspx file like:

  1. <asp:Repeater ID="Repeater1" runat="server">  
  2.     <ItemTemplate>  
  3.         <div>  
  4.             <table>  
  5.                 <tr>  
  6.                     <th>Student  
  7.                         <%#Eval("S_ID")%>  
  8.                     </th>  
  9.                 </tr>  
  10.                 <tr>  
  11.                     <td>Student Name</td>  
  12.                     <td>  
  13.                         <%#Eval("Student_Name")%>  
  14.                     </td>  
  15.                 </tr>  
  16.                 <tr>  
  17.                     <td>Registration Number</td>  
  18.                     <td>  
  19.                         <%#Eval("Register_No")%>  
  20.                     </td>  
  21.                 </tr>  
  22.                 <tr>  
  23.                     <td>Date Of Birth</td>  
  24.                     <td>  
  25.                         <%#Eval("D_O_B")%>  
  26.                     </td>  
  27.                 </tr>  
  28.                 <tr>  
  29.                     <td>Date Of Examination</td>  
  30.                     <td>  
  31.                         <%#Eval("D_O_E")%>  
  32.                     </td>  
  33.                 </tr>  
  34.                 <tr>  
  35.                     <td>Department</td>  
  36.                     <td>  
  37.                         <%#Eval("Department")%>  
  38.                     </td>  
  39.                 </tr>  
  40.             </table>  
  41.         </div>  
  42.     </ItemTemplate>  
  43. </asp:Repeater>  

When you run this page the output will look like:

output

Related questions

0 votes
0 votes
    What is Data Cache in ASP.NET and how to use?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    How can we improve the Performance of an ASP.NET Web Page?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    How can we apply themes in ASP.NET application?...
asked Apr 6, 2021 in Education by JackTerrance
0 votes
    What is Enterprise Library in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    What are the Navigations techniques in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    Explain Cookie-less Session in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is the PostBack property in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is cross-page posting in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What are the differences between ASP.NET HttpHandler and HttpModule?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the difference between HttpContext.Current.Items and HttpContext.Current.Session in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What are different methods of session maintenance in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
...