C# : Tutorial of Asp.net with c# and example

Example and code about windows application, web application, SQL, C#, WPF etc which is helpful to developer and programer.

Search This Blog

C#: how to bind data in repeater control in asp.net? and example of repeater with c# code

♠ Posted by uvesh master in ,, at Friday, August 08, 2014

What is Repeater Control?



Repeater Control is a control of asp.net which is used to display the data which is daynamic and repeatedly change collection of record


How to work repeater control of asp.net?

The Repeater control works by looping through the records in your data source and then repeating the rendering of
it’s templates called item template.
Repeater control contains different types of template fields those are

1) itemTemplate
2) AlternatingitemTemplate
3) HeaderTemplate
4) FooterTemplate
5) SeperatorTemplate


what is use of ItemTemplate in repeater control of asp.net?

ItemTemplate defines how the each item is rendered from dataBase collection.


what is use of AlternatingItemTemplate in repeater control of asp.net?


AlternatingItemTemplates is used to change the background color and styles of AlternatingItems in DataBase collection


what is use of HeaderTemplate in repeater control of asp.net?


HeaderTemplate is used to display Header text for DataSource collection and apply different styles for header text.


what is use of FooterTemplate in repeater control of asp.net?

FooterTemplate is used to display footer element for Data collection


what is use of SeparatorTemplate in repeater control of asp.net?

SeparatorTemplate will determine separator element which separates each Item in Item collection. Usually, SeparateTemplate will be <br> html tag or <hr> html tag.


How to Design of repeater control?


<asp:Repeater ID="Reptrsexample" runat="server">
<HeaderTemplate>
<table >
<tr >
<td colspan="2">
<b>header</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr >
<td>
<table>
<tr>
<td>
data:
<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("field_name") %>' Font-Bold="true"/>
</td>
</tr>
</table>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>


How to Bind data in repeater by use of C#?

Import following name space

using System;
using System.Data;
using System.Data.SqlClient;


protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindRepeaterData();
}
}


protected void BindRepeaterData()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Repeater_Table", con);
DataSet ds = new DataSet();
SqlDataAdapter dadp = new SqlDataAdapter(cmd);
dadp.Fill(ds);
Reptrsexample.DataSource = ds;
Reptrsexample.DataBind();
con.Close();
}



Improve Your Answer as comment below.

If our post is useful please share and comment on our post for more post and detail Visit :


http://aspdotnethelpmaster.blogspot.in/
 

0 comments:

Post a Comment