Wednesday, August 8, 2012

Working with Repeater Control

Repeater Control

This Control is used to display the data in plain Text.

Repeater Control does not provide designing Facilities, Editing Facilities, Sorting Facilities

It is faster as compared to GridView, DataList

It is just used to display the data in plane format.














Default.aspx


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <asp:Repeater ID="Repeater1" runat="server">
        <HeaderTemplate>
        <tr>
        <th>
        EmpNo
        </th>
        <th>
        EmpName
        </th>
        <th>
        Designation
        </th>
        </tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr>
        <td> <%#DataBinder.Eval(Container.DataItem,"eno")%></td>
        <td> <%#DataBinder.Eval(Container.DataItem,"ename")%></td>
        <td><%#DataBinder.Eval(Container.DataItem,"designation")%></td>
        </tr>
        </ItemTemplate>
        </asp:Repeater>
    </table>
    </div>
    </form>
</body>
</html>



Default.aspx.cs


using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class RepeaterControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("user id=sa;password=uday;database=uday;data source=localhost");
        SqlCommand cmd = new SqlCommand("select *from employee", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Repeater1.DataSource = ds;
        Repeater1.DataBind();
    }
}





No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...