The Repeater control is a container control that allows you to create custom lists out of any data that is available to the page. In Repeater control doesn’t have built in rendering of its own so we have to provide the layout for the Repeater control. Repeater control uses following Templates,

Repeater Control Templates:

ItemTemplate: It contains HTML elements and controls to Render each data item in the datasource.

AlternatingItemTemplate: It render data same sa ItemTemplate but it’s used to create different look for alternate data rows.  

HeaderTemplate and FooterTemplate: Contains the text and controls to render at the beginning and end of the list, respectively.

SeparatorTemplate: Contains the elements to render between each item. A typical example might be a line (using an HR element).

Advantages of Repeater Control:

Personally I always try to use simplest control necessary to do the job. You'll generally find that the more features a control has, the more 'heavy' it will be. As well as increasing ViewState size, heavier controls also have a greater hit on CPU load and memory requirements.

Performance of repeater is far better than GridView. If you need basic rendering for read only items then it’s better to use Repeater Control, and if you need events, pagination and editable controls then you should go for GridView. Simpler controls with less in built functionality are speedy like Repeater Control.

Bind Repeater Control:

          It’s quite easy to bind Repeater Control. When the page runs, the Repeater control loops through the records in the data source and renders an item for each record.

HTML Code:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Repeater control example</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Repeater ID="Repeater1" runat="server">

            <HeaderTemplate>

                <table cellpadding="1" cellspacing="1" width="50%" style="font-family: Calibri;

                    border: 1px solid #C0C0C0; background-color: #D8D8D8">

                    <tr style="background-color:Gray; color:White">

                        <th>Employee-ID </th>

                        <th> Name </th>

                        <th> Designation </th>

                        <th> City </th>

                        <th> Country </th>

                    </tr>

            </HeaderTemplate>

            <ItemTemplate>

                <tr style="background-color: White">

                     <td> <%#DataBinder.Eval(Container, "DataItem.empid")%>  </td>

                    <td>  <%#DataBinder.Eval(Container, "DataItem.name")%> </td>

                    <td>  <%#DataBinder.Eval(Container, "DataItem.designation")%>  </td>

                    <td>  <%#DataBinder.Eval(Container, "DataItem.city")%> </td>

                    <td <%#DataBinder.Eval(Container, "DataItem.country")%> </td>

                </tr>

            </ItemTemplate>

            <AlternatingItemTemplate>

                <tr style="background-color:#AED6FF">

                    <td>  <%#DataBinder.Eval(Container, "DataItem.empid")%> </td>

                    <td> <%#DataBinder.Eval(Container, "DataItem.name")%> </td>

                    <td>  <%#DataBinder.Eval(Container, "DataItem.designation")%> </td>

                    <td <%#DataBinder.Eval(Container, "DataItem.city")%> </td>

                    <td>  <%#DataBinder.Eval(Container, "DataItem.country")%> </td>

                </tr>

            </AlternatingItemTemplate>

            <FooterTemplate>

                </table>

            </FooterTemplate>

        </asp:Repeater>

    </div>

    </form>

</body>

</html>

 

C# code:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

public partial class _Default : System.Web.UI.Page

{

   SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            BindData();

        }

    }

    protected void BindData()

    {

        DataSet ds = new DataSet();   

        conn.Open();

        string cmdstr = "Select * from EmployeeDetails";

        SqlCommand cmd = new SqlCommand(cmdstr, conn);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);

        adp.Fill(ds);

        Repeater1.DataSource = ds;

        Repeater1.DataBind();

        conn.Close();

    }

}

 

cytotec abortion

abortion pill online buy abortion pills online
medical abortion pill online cytotec abortion abortion pill


View demo Download
http://www.dotnetfox.com/Document/1110/0Demo1.gif

If you enjoyed this article, get email updates (it's free).



Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox