Feature & Difference between Gridview,DataList and Repeater control

DataGrid and DataList controls are derived from the WebControl class, while the Repeater control is derived from the Control class. The WebControl class contains a number of aesthetic properties, such as BackColor, ForeColor, CssClass, BorderStyle and so on.
In ASP .NET basically there are three kinds of the Data Presentation Controls.
  • GridView or DataGrid
  • DataList
  • Repeater
List of different abilities of Repeater Control, Datalist Control and GridView Control features.

Features of a GridView:
  1. Displays data as a table
  2. Updateable
  3. Item as row
  4. Control over
  • Alternate item
  • Header
  • Footer
  • Colors, font, borders, etc.
  • Paging
Features of Repeater:
  1. List format
  2. No default output
  3. More control
  4. More complexity
  5. Item as row
  6. Not updateable
Features of DataList:
  1. Directional rendering
  2. Good for columns
  3. Item as cell
  4. Alternate item
  5. Updateable
Difference between Datagrid,DataList and Data Repeater:
  • Datagrid has paging while Datalist doesnt.
  • Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
  • A repeater is used when more intimate control over html generation is required.
  • When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid.
The Repeater repeats a layout of HTML you write, it has the least functionality of the three. DataList is the next step up from a Repeater; accept you have very little control over the HTML that the control renders. DataList is the first of the three controls that allow you Repeat-Columns horizontally or vertically. Finally, the DataGrid is the motherload. However, instead of working on a row-by-row basis, you’re working on a column-by-column basis. DataGrid caters to sorting and has basic paging for your disposal. Again you have little contro, over the HTML. NOTE: DataList and DataGrid both render as HTML tables by default.


GridView example:


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridView example</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:GridView ID="GridViewExample" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
<asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle"
SortExpression="ContactTitle" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="Region" HeaderText="Region"
SortExpression="Region" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode"
SortExpression="PostalCode" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConnectionString1 %>"
SelectCommand="SELECT * FROM [Company]"></asp:SqlDataSource>

</div>
</form>
</body>
</html>


DataList Example:


<h2 style="color: Green">
DataList in ASP.NET using C#</h2>
<asp:DataList ID="DataListExample" runat="server" BackColor="#DEBA84" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
DataSourceID="SqlDataSource1"
Font-Bold="True" Font-Names="Verdana" Font-Size="Small" GridLines="Both" RepeatColumns="2"
RepeatDirection="Horizontal" Width="463px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" Font-Size="Large" ForeColor="White"
HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderTemplate>
Student Information
</HeaderTemplate>
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<ItemTemplate>
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'
ForeColor="#000099" />
<br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
Age:
<asp:Label ID="AgeLabel" runat="server" Text='<%# Eval("Age") %>' />
<br />
Course:
<asp:Label ID="CourseLabel" runat="server" Text='<%# Eval("Course") %>' />
<br />
Branch:
<asp:Label ID="BranchLabel" runat="server" Text='<%# Eval("Branch") %>' />
<br />
City:
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
<br />
MobileNo:
<asp:Label ID="MobileNoLabel" runat="server" Text='<%# Eval("MobileNo") %>' />
<br />
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>
<br />

Repeater Example:

<asp:Repeater ID="NewsListRepeater" runat="server" DataSourceID="SqlDataSource1">

<HeaderTemplate>Repeater Example<br /><br /></HeaderTemplate>

<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "TestEnglish") %><br />
<%# DataBinder.Eval(Container.DataItem, "TestMath") %><br />
</ItemTemplate>

<SeparatorTemplate>
******<br />
</SeparatorTemplate>

<AlternatingItemTemplate>
<i><%# DataBinder.Eval(Container.DataItem, "TestEnglish") %></i><br />
<i><%# DataBinder.Eval(Container.DataItem, "TestMath") %></i><br />
</AlternatingItemTemplate>

<FooterTemplate><br />End of the funky stuff</FooterTemplate>

</asp:Repeater>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>"
SelectCommand="SELECT * FROM [Student]"></asp:SqlDataSource>

Related Topic:



Tags: , , , , , ,
Hot on Web:


About author