How to display data in Repeater ?

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 883
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>
Column Header Name 1
</th>
<th>
Column Header Name 2
</th>
<th>
Column Header Name 3
</th>
<th>
Column Header Name 4
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#Eval("Header_Column_1")%>
</td>
<td>
<%#Eval("Header_Column_2")%>
</td>
<td>
<%#Eval("Header_Column_3")%>
</td>
<td>
<%#Eval("Header_Column_4")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>

C# Code :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
public void BindData()
{
try
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Table_Name", con);
DataTable ds = new DataTable();
da.Fill(ds);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
catch (Exception ex)
{
Label1.Text = ex.Message.ToString();
}
finally
{
con.Close();
}
}

Comments or Responses

Login to post response