The tabular DataBound controls are the main set of controls that we use when working
with database data. These controls enable we to display and, in some cases, modify data
retrieved from a database or other type of data source.
Six tabular DataBound controls can be divided into two types:
1) Display multiple data items at a time
2) Display single data item at a time
we can use any of the following controls to display a set of data items:
S.N.
|
Controls
|
Description
|
1)
|
GridView
|
Displays a set of data items in an HTML table.
This control enables we to display, sort, page, select, and edit data.
|
2)
|
DataList
|
Displays a set of data items in an HTML table. Unlike the GridView
control, more than one data item can display in a single row.
|
3)
|
Repeater
|
Displays a set of data items using a template. Unlike the GridView and
DataList controls, a Repeater control does not automatically render an HTML table.
|
4)
|
ListView
|
Displays a set of data items using a template. Unlike the
Repeater control, the ListView control supports sorting, paging, and editing database data.
|
We can use either of the following two controls to display a single data item at a time:
S.N.
|
Controls
|
Description
|
1)
|
DetailsView
|
Displays a single data item in an HTML table.
This control enables we to display, page, edit, and add data.
|
2)
|
FormView
|
Uses a template to display a single data item. Unlike the DetailsView,
a FormView enables we to use to layout a form by using templates.
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TabularDataBoundEx01.aspx.cs"
Inherits="LearnAsp.Net.ControlDemo.DataBound.TabularDataBoundEx01" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type="text/css">
.floater
{
float: left;
border: solid 1px black;
padding: 5px;
margin: 5px;
}
</style>
<title>Show Tabular Databound Controls</title>
</head>
<body>
<form id="form1" runat="server">
<div class="floater">
<h3>
GridView</h3>
<asp:GridView ID="GridView1" DataSourceID="srcDept" runat="server" />
</div>
<div class="floater">
<h3>
DataList</h3>
<asp:DataList ID="DataList1" DataSourceID="srcDept" RepeatColumns="2" runat="server">
<ItemTemplate>
<%#Eval("department_id")%>
<i>directed by</i>
<%#Eval("department_name")%>
</ItemTemplate>
</asp:DataList>
</div>
<br style="clear: both" />
<div class="floater">
<h3>
DetailsView</h3>
<asp:DetailsView ID="DetailsView1" DataSourceID="srcDept" AllowPaging="true" runat="server" />
</div>
<div class="floater">
<h3>
FormView</h3>
<asp:FormView ID="FormView1" DataSourceID="srcDept" AllowPaging="true" runat="server">
<ItemTemplate>
<%#Eval("department_id")%>
<i>directed by</i>
<%#Eval("department_name")%>
</ItemTemplate>
</asp:FormView>
</div>
<br style="clear: both" />
<div class="floater">
<h3>
Repeater</h3>
<asp:Repeater ID="Repeater1" DataSourceID="srcDept" runat="server">
<ItemTemplate>
<%#Eval("department_id")%>
<i>directed by</i>
<%#Eval("department_name")%>
</ItemTemplate>
</asp:Repeater>
</div>
<div class="floater">
<h3>
ListView</h3>
<asp:ListView ID="ListView1" DataSourceID="srcDept" runat="server" ItemPlaceholderID="myitemplaceholder">
<LayoutTemplate>
<asp:PlaceHolder ID="myitemplaceholder" runat="server"></asp:PlaceHolder>
<div id="itemContainer" runat="server">
</div>
<asp:DataPager ID="pager1" PageSize="3" runat="server">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<%#Eval("department_id")%>
<i>directed by</i>
<%#Eval("department_name")%>
</ItemTemplate>
</asp:ListView>
</div>
<asp:SqlDataSource ID="srcDept"
ConnectionString="data source=LearnAsp;user id=LearnAsp;password=LearnAsp; Pooling=true;
Max pool size=200; Min pool size=0;"
ProviderName="System.Data.OracleClient"
SelectCommand=" SELECT department_id,department_name FROM departments where rownum <=5"
runat="server" />
</form>
</body>
</html>
No comments:
Post a Comment
Please do not enter any spam link in the comment box.