Monday, July 13, 2009

Databinding with Repeater control in asp.net with C#

Data presentation is an important goals of any application development process. ASP.NET 2.0 provides many server controlswhich render data in different rich formats and styles. for example Datalist, Gridview, repeater control etc. Here I am going to discuss about repeater control in detail.

Repeater control is a template based container control. you define layout for the Repeater control by creating different templates based on your needs. The Repeater control may be bound to a database table, an XML file, or another list of items. Here we will show how to bind data to a Repeater control.

Repeater Control Templates

Repeater controls provides different kinds of templates which helps in determining the layout of control's content. Templates generate markup which determine final layout of content. These are as follows:

  • HeaderTemplate
  • ItemTemplate
  • AlternatingItemTemplate
  • FooterTemplate
  • SeparatorTemplate

ItemTemplate: ItemTemplate defines how the each item is rendered from data source collection.

AlternatingItemTemplate: AlternatingItemTemplates define the markup for each Item but for AlternatingItems in DataSource collection like different background color and styles.

HeaderTemplate: HeaderTemplate will emit markup for Header element for DataSource collection

FooterTemplate: FooterTemplate will emit markup for footer element for DataSource collection

SeparatorTemplate: SeparatorTemplate will determine separator element which separates each Item in Item collection. Usually, SeparateTemplate will be
html element or


html element.

DataBinding in Repeater Control:

Like any other Data Bound control, Repeater control supports DataSource property which allows you to bind any valid DataSource, any datasets or XML files.

There are the following easy steps to bind repeater control.

Step 1: Create new web application.

Step 2: Drag repeater control from toolbox and drop on the page.

Step 3: add the varies templates like as follows:

InlineCode:


See full detail: http://www.c-sharpcorner.com/UploadFile/prathore/RepeaterControl06162009024228AM/RepeaterControl.aspx

No comments: