IT Community - Software Programming, Web Development and Technical Support

Difference between DataList and Repeater?

This is a discussion on Difference between DataList and Repeater? within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi, Differentiate DataList and Repeater.......


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 01-24-2008, 01:10 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Difference between DataList and Repeater?

Hi,
Differentiate DataList and Repeater....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 02:16 AM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Re: Difference between DataList and Repeater?

Hi poornima

below link will explain you about Difference between DataList and Repeater

http://www.discussweb.com/vb-net-pro...-datagrid.html

Thanks
KirthiKa

Last edited by KiruthikaSambandam : 01-24-2008 at 06:12 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-24-2008, 06:08 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: Difference between DataList and Repeater?

hi kiruthika,
Thanks .the link given by listed the difference between three controls clearly.

Last edited by poornima : 01-24-2008 at 06:10 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-24-2008, 09:16 AM
ammulu ammulu is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 105
ammulu is on a distinguished road
Default Re: Difference between DataList and Repeater?

Hi Poornima,
Check out this link for a brief note about the difference between 3 controls:
ASP.NET.4GuysFromRolla.com: Understanding the Differences Among the DataGrid, DataList, and Repeater
Hope this helps.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-25-2008, 01:20 AM
poornima poornima is offline
D-Web Sr.Programmer
 
Join Date: Dec 2007
Posts: 189
poornima is on a distinguished road
Smile Re: Difference between DataList and Repeater?

Hi ammulu,
Thanks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-25-2008, 03:27 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

Understanding the Differences Among the DataGrid, DataList, and Repeater

Introduction
One of the many benefits of ASP.NET over its predecessor, ASP, is ASP.NET's data Web controls. The data Web controls are designed to easily display data. For example, the DataGrid Web control is ideal for displaying data in an HTML <table>. (For more information on the DataGrid Web control be sure to read An Extensive Examination of the DataGrid Web Control.) In addition to the DataGrid Web control, there are two additional data Web controls. All in total, the three ASP.NET data Web controls are:
  1. The DataGrid,
  2. The DataList, and
  3. The Repeater
These three controls share much in common, such as the programmatic syntax used for binding data to the Web control, as well as a number of common properties and events. Despite their similarities, though, each of these Web controls has their individual advantages and disadvantages. In designing data-driven Web applications, ASP.NET developers often find themselves wondering which of these three controls is the "best" one.
The answer to that question depends on what it is you are needing to accomplish. In this article we'll examine the merits and demerits of each of these three data Web controls, and look at situations where certain controls have benefits over the others. Additionally, we'll examine not only the different advantages and disadvantages, but what things these three controls have in common.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-25-2008, 03:28 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

Examining the Similarities Between the Data Web Controls
The main similarity between the DataGrid, DataList, and Repeater Web controls is that all three have a DataSource property and a DataBind() method. In order to bind data to one of these data Web controls, the same technique is used:
  1. Assign the data to be displayed to the data Web control's DataSource property, and
  2. Call the data Web control's DataBind() method.
Another similarity is that each of the data Web controls is composed of a given number of DataWebControlNameItems. That is, a DataGrid is composed of a number of DataGridItems; the DataList of DataListItems; and the Repeater of RepeaterItems. When the data Web control's DataBind() method is called, it iterates through the contents of the DataSource. For each record in the DataSource, a new DataWebControlNameItem instance is created and appended to the data Web control. After the DataWebControlNameItem instance has been created, its DataItem property is assigned the value of the current DataSource record and the DataWebControlNameItem's DataBind() method is called, which binds the columns of the DataSource record to the DataWebControlNameItem. (The DataGridItem, DataListItem, and RepeaterItem differ in a number of ways, which we'll discuss later in this article.)
In addition to these similarities, the data Web controls each also have the following three events:
  1. ItemCreated,
  2. ItemDataBound, and
  3. ItemCommand
The ItemCreated event fires once for every DataWebControlNameItem added to the data Web control. It fires before the DataWebControlNameItem's DataItem property is assigned. The ItemDataBound event also fires once for every DataWebControlNameItem added to the data Web control, but this event fires after the DataWebControlNameItem's DataItem property is assigned. Finally, the ItemCommand event fires whenever the Command event for a Button or LinkButton within the data Web control fires.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-25-2008, 03:29 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

Demystifying these Similarities With an Example
If you are thoroughly confused right about now, I don't blame you! The process a data Web control undergoes when being bound to data can be a bit perplexing at first. However, it is oftentimes much easier to comprehend these complexities by looking at an example. Consider the case where we have a DataGrid that contains two BoundColumns. Such a DataGrid declaration might look like:
<asp:DataGrid runat="server" id="myDataGrid" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Field1" />
<asp:BoundColumn DataField="Field2" />
</Columns>
</asp:DataGrid>

Now, imagine that we are binding a DataSet to this DataGrid in the Page_Load event handler. To accomplish this, we might use the following code:
Sub Page_Load(sender as Object, e as EventArgs)
Dim myConnection as New SqlConnection(connString)
Const strSQL as String = "SELECT Field1, Field2 FROM TableName"

Dim resultsDataSet as New DataSet()
Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection)
myDataAdapter.Fill(resultsDataSet)

myDataGrid.DataSource = resultsDataSet
myDataGrid.DataBind()
End Sub

What happens when the DataGrid's DataBind() method is called? As we discussed earlier, the DataGrid's DataBind() method enumerates the records of the DataSet assigned to its DataSource property (namely, resultsDataSet). Realize that when iterating through the DataSet, in actuality you are iterating through the Rows collection of the DataSet's default DataTable. The Rows collection is comprised of a number of DataRow instances, one for each record returned by the specified SQL query.
Now, for each DataRow, first, a new DataGridItem is created. Then, the DataGrid's ItemCreated event fires. Next, the DataRow is assigned to the DataGridItem's DataItem property. Following this, the DataGrid's ItemDataBound event fires. This process is repeated for all of the DataRows.
This databinding process is common among the three data Web controls, the only difference being that with a DataList or Repeater a DataListItem or RepeaterItem is created in place of a DataGridItem.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-25-2008, 03:29 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

A Brief Overview of the DataGrid Web Control
The DataGrid Web control was designed to display data in an HTML <table>. Each row in the DataGrid's DataSource is displayed as a row in the HTML <table>. The DataGrid has an AutoGenerateColumns property, which can be set to either True or False. If AutoGenerateColumns is set to True (the default), each field in the DataSource is displayed as a column in the resulting HTML <table>. If, however, AutoGenerateColumns is set to False, then the developer must explicitly specify what columns should appear.
One downside of a DataGrid is its rather "blocky" display. That is, the DataGrid displays each DataSource record as a row in an HTML <table>, and each field as a column in said table. While the DataGrid allows for the developer to customize the output for a particular column through the <asp:TemplateColumn>, it still is restrictive in that each DataSource record occupies precisely one HTML <table> row. (For an example of customizing a DataGrid's column using templates, see Combining Two DataSource Fields Into One DataGrid Column.)
Despite its limitations on specifying the display of the DataGrid's data, the DataGrid is the most commonly used data Web control due to its impressive feature list. For example, with minimal code and effort, the DataGrid can provide sorting, paging, and in-place editing of its data. (For more on the DataGrid Web control, as well as thorough coverage of its features, be sure to read An Extensive Examination of the DataGrid Web Control.)
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-25-2008, 03:30 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

A Brief Overview of the DataList Web Control
The DataList Web control is useful for displaying data that can be highly customized in its layout. By default, the DataList displays its data in an HTML <table>. However, unlike the DataGrid, with the DataList you can specify via the RepeatColumns how many DataSource records should appear per HTML <table> row. For example, the following code and live demo illustrates having five DataSource records displayed per HTML <table> row.
<asp:DataList runat="server" id="dlPopularFAQs"
...
RepeatColumns="5" >
<ItemTemplate>
<b>Question:</b><br />
<%# DataBinder.Eval(Container.DataItem, "Description") %>
<p>
<b>Views:</b><br />
<%# DataBinder.Eval(Container.DataItem, "ViewCount", "{0:#,###}") %>
</ItemTemplate>
</asp:DataList>



As the code example above shows, DataLists are comprised of a number of templates. Templates can contain a mix of HTML syntax and databinding expressions, as shown in the above ItemTemplate. Databinding expressions are ones delimited by <%# and %>, and contain code that's executed when the DataListItem's DataBind() method is called. The ItemTemplate specifies the template used for each record in the DataSource. The DataList contains other templates, which are listed below:
  • AlternatingItemTemplate - if specified, each alternating item in DataSource uses this template instead of the ItemTemplate.
  • EditItemTemplate - the template used when a DataList row is in "edit mode".
  • HeaderTemplate - the template for the DataList's header item. Precisely one header item is created for the DataList item if the DataList's ShowHeader property is set to True.
  • FooterTemplate - the template for the DataList's footer item. Precisely one footer item is created for the DataList item if the DataList's ShowFooter property is set to True.
  • SeparatorTemplate - this template, if specified, is applied after each DataListItem has been added.
The DataList is capable of performing sorting, paging, and editing of its data, but to do so requires quite a bit more programming than to accomplish these tasks with the DataGrid. Therefore, if you know you will be needing these functionalities, it is likely best to proceed with the DataGrid. If, however, you will not need these functionalities, but do necessarily need the extra control over the formatting, consider a DataList.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 01-25-2008, 03:32 AM
rrrajesh84in rrrajesh84in is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 399
rrrajesh84in is on a distinguished road
Default Re: Difference between DataList and Repeater?

A Brief Overview of the Repeater Control
The Repeater control, unlike the DataGrid and DataList, is not derived from the WebControl class, and therefore does not have the stylistic properties that are common to all Web controls. (These stylistic properties that are common to all Web controls include Font, ForeColor, BackColor, BorderStyle, and so on.)
The Repeater, like the DataList, only supports templates; however, the Repeater has only a subset of the DataList's template options. Specifically, the following templates can be used with the Repeater:
  • AlternatingItemTemplate,
  • ItemTemplate,
  • HeaderTemplate,
  • FooterTemplate, and
  • SeparatorTemplate
The Repeater control provides the maximum amount of flexibility over the HTML produced. Whereas the DataGrid wraps the DataSource contents in an HTML <table>, and the DataList wraps the contents in either an HTML <table> or <span> tags (depending on the DataList's RepeatLayout property), the Repeater adds absolutely no HTML content other than what you explicitly specify in the templates.
Therefore, the Repeater is a good data Web control choice if you want to display data in, say, an unordered list. As the following code and live demo show, displaying database data in an unordered list using a Repeater is relatively straightforward. All you have to do is add the <ul> tag to the HeaderTemplate, the </ul> tag to the FooterTemplate, and an <li> tag along with the DataSource field you want to display to the ItemTemplate:
<asp:Repeater runat="server" id="rptULforFAQs">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><%# DataBinder.Eval(Container.DataItem, "Description")%></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>



The Repeater is a good choice if you need to display your data in a format different than an HTML <table>. Unfortunately, the Repeater does not provide any built-in means for editing, sorting, or paging of data. However, these mechanisms could be added programmatically, but would result in a lot of code and effort.
Conclusion
This article examined the similarities and differences of the three data Web controls: the DataGrid, DataList, and Repeater. The main similarities between these three controls is in how they iterate through their DataSource, building up a collection of DataWebControlNameItems. Furthermore, the three Web controls all share three events: ItemCreated, ItemDataBound, and ItemCommand.
Each of the data Web controls has its own strengths and weaknesses. The DataGrid, for example, is great for quickly and easily displaying database data in an HTML <table>, and allows for advanced features such as paging, sorting, and in-place editing to be added with little to no programming. However, the DataGrid is quite limited in the general format with which the data is presented.
The DataList allows for more freedom. For example, in an earlier live demo we saw that using the DataList's RepeatColumns property, multiple DataSource records could be displayed in a single HTML <table> row. Additionally, the DataList's content is specified via templates, which allows for a high degree of customization.
The Repeater allows for the utmost flexibility in its output, since the only HTML rendered from a Repeater is the HTML generated in its templates. That is, no additional HTML output is generated, as is the case with both the DataGrid and DataList. The Repeater, however, does not have any built-in support for sorting, paging, or editing of its data.
__________________
.....................................
''''''
Rajesh''''''
Ants. . . . . . Like me
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/asp-asp-net-programming/5089-difference-between-datalist-repeater.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 01-24-2008 04:21 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is the best among DataList,Repeater and GridView and Why? poornima ASP and ASP.NET Programming 2 03-14-2008 08:44 PM
How to implement Custom Paging in DataList? poornima ASP and ASP.NET Programming 0 01-24-2008 12:57 AM
What is the difference between repeater over datalist and datagrid? anbuchezhians VB.NET Programming 5 11-22-2007 04:44 AM
How to decide on the design consideration to take a Datagrid, datalist or repeater in oxygen ASP and ASP.NET Programming 1 07-26-2007 04:09 AM
How to add a TemplateColumn dynamically to Repeater? in .net kingmaker C# Programming 1 07-26-2007 01:02 AM


All times are GMT -7. The time now is 07:36 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0