In .aspx page Write NameSpace just below page Directive
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default " %>
<%@
Import Namespace="System.Data.SqlClient" %>
Write the below code in tag
<script runat="server">
protected void Page_Load(object sender, EventArgs
e)
{
SqlConnection dbconn;
SqlCommand dbcomm;
SqlDataReader dreader;
string sqlQry;
dbconn = new SqlConnection("Data Source=local;Initial Catalog=MyDB;Integrated
Security=True");
dbconn.Open();
sqlQry = "SELECT TOP 10 ID, Sal, FName, LName FROM Employee";
dbcomm = new SqlCommand(sqlQry,
dbconn);
dreader =
dbcomm.ExecuteReader();
repEmployee.DataSource
= dreader;
repEmployee.DataBind();
dreader.Close();
dbconn.Close();
}
</script>
Declare Repeater Control
as below:
<div>
<asp:Repeater id="repEmployee" runat="server">
<HeaderTemplate>
<table border="1" width="50%">
<tr>
<th>ID</th>
<th>Sal.</th>
<th>F.Name</th>
<th>L.Name</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("ID")%></td>
<td><%#Eval("Sal")%></td>
<td><%#Eval("FName")%></td>
<td><%#Eval("LName")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
I hope you will enjoy.
Cheers.
Comments