Asp.net unit-4
Asp.net unit-4
11 YEAR V SEMESTER D
BCA 7
In
provider that supplies site map information.
SiteMapDataSource: It allows binding to a
The data source controls used tor tabular data are: S
9
Descrlption
SI. No. Data source controls provider that U
1 represents a connection to an ADO.NET dataaccessible yia 10
SqlDataSource It data sources
returns SQL data, including
OLEDB and ODBC.
returns 11
2 allows binding to a custom .Net business object that
ObjectDataSource It
data.
Ling-to-SQL query 12
3 LinqdataSource It allows binding to the results of a
(supported by ASPNET 3.5 only).
Access database.
4 AccessDataSource It represents connection to a Microsoft The SqlDa
Data Source Views TheS
Data source views ane objects of the DataSourceiew class. Which represent a customized view of Oradedatat
data for different data operations such as sorting, filtering, etc.
p data is m
The DataSourceView class serves as the base class for all data source view classes, which define the The fo
capabilities of data source controls. <asp
The following table provides the properties of the DataSourceView class: Provi
SLNo. Properties Description Conn
1 CanDelete Indicates whether deletion is allowed on the underlying data source. Selec
2 Caninsert Indicates whether insertion is allowed on the underlying data source. <asp
Conf
3. CanPage Indicates whether paging is allowed on the underlying data source.
4 CanRetrieve Indicates whether total row count information is available. property g
TotalRowCount The
5. CanSort Indicates whether the data could be sorted. Provides th
6. CanUpdate Indicates whether updates are allowed on the
underlying data source.
SLNo.
7. Events Gets a list of event-handler 1
delegates for the data source view.
8. Narne Name of the view.
7. Delete Performs adelete operation on the data associated with the view.
8. Insert Performs an insert operation on the data associated with the
view.
9 Select Pourns the oueried data.
10 Update Perlorms an update operation on the data associated with the
view.
11
OnDataSourceVey Raises the DataSourceViewChanged event.
Changed
12
RaiseUnsupported Called by the RaiseUnsupportedCapabilitiesEror method to
CapabilitiesError compare the capabilities requested for an ExecuteSelect
operation against those that the view supports.
The SqlDataSource Control
he sqbataSource contral represents a connection to a relational database such as SQL Server or
Oracle database, or data accessible through OLEDB or Open Database Connectivity (ODBC). Connection
to data is made through two important properties ConnectionString and
ProviderName.
The following code snippet provides the basic syntax of the control:
<asp:SqlDataSource runat="server" ID="MySqSource"
ProviderName'<%$ ConnectionStrings:LocalNWind. ProviderName %>'
ConnectionString '<$ ConnectionStrings: LocalNWind %>
SelectionCommand "SELECT FROM EMPLOYEES" I>
<asp:GridViewlD="GridViewl"runat="server"Data SourcelD ="MySqlSource"/>
Configuring various data operations on the underlying data depends upon the various properties
(property groups) of the data source control
The following table provides the related setsof properties of the SqlDataSource control, which
provides the programming intert ce of the control
SI.No. Property Group Description
1 DeleteCommand. Gets or sets the SQL statement, parameters, and type for
DeleteParameters, deleting rows in the underlying data.
DeleteCommandType
2 FilterExpression, Gets or sets the data filtering string and parameters.
FilterParameters
3 InsertCommand, Gets or sets the SQL staternent, pararneters, and type for
InsertParameters, inserting rows in the underlying database.
InsertCommandType
4 SelectCommand, Gets or sets the SQL statement, parameters, and type for
SelectParameters, retrieving rows from the underlying database.
SelectCommandType
SortParameterName Gets or sets the name of an input parameter that the
command's stored procedure will use to sort data,.
5 UpdatcCommand, Gets or sets the SQL staterment, parameters, and type for
UpdateParameters, updating rows in the underlying data store.
UpdateCommandlype
151
Ruhul Publications
l YEARV SEMESIEP
BCA
Text='<%#Eval
Font Bold"true"
:<asp Label ID"bIDate" nunat"server"
Date:<
("PostedDate") %>/> <Ad>
</r>
<Aable>
<td>«>
td lsan-"2> , </td>
temTemplate>
<Footer Template>
table
<FooterTemplate>
< asp.Repeater>
< div></tom>
Datalist is a Databound control to display and manipulate data in a web application. It is a composite
control that can combine other ASPNet controls and it is present in the form. The Datalist appearance is
conroled by its ternplate fields.
The following template fields are supported by the DataList control:
Jtemtemplate: It specifies the Iterns present in the Datasource, it renders itself in the browser as
many rows present in the data source collection.
EdititemTemplate: Used to provide edit permissions to the user.
HeaderTemplate: Used to display header text to the data source collection.
FooterTemplate: Used to display footer text to the data source collectian.
ItemStyle: Used to apply styles to an ItemTemplate.
EditStyle: Used to apply styles to an EditltemTenplate
HeaderStyle: Used to apply styles to a HeaderTemplate
FooterStyle: Used to apply styles to a FooterTemplate.
158
Rahul Publications
NIT
- IV PROGRAMMING USING ASP NET
Frequently used properties with DataList
Propertv Name
RepeatDirection Desciption
Used to set or get the Direction of iferns
Horizontal
being rendet
\'ertical(Detault) Horizontal Items will render in Hori zontal
\ertical Itens will rendet in Vetica!
with DataTable
ASPNET DataList Example
1|DataListExample2.aspx "DataListExample2.
AutoEventWireup= "rue" CodeBehind=
="C#"
<%@ Page Language
aspx.cs"
Inherits ="DataListExample.DatalListExample2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="'server>
<title></title>
</head>
<body> runat="server">
<form id="form1"
<div>
Rahul Publications
{159
BCA YEAR V SEMESTEP
<td>
Eval("ID'")
<b>ID: </b><span class ="city"><%#
%> </span> <br />
<b>Name: </b><span class="postal">
<%# Eval("Namne") %> </span><br />
<b>Email: </b><span class="country'>
<%# Eval("Email") %></span><br />
</td> </tr>
</table>
</ItemTemplate>
</asp:DataList>
</form>
</body> </html>
CodeBehind
/ DataListExample2.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Ling;
using Systern.Web:
using System.Web.Ui;
using System.Web.UI.WebControls:;
namespace DataListExample
160
Rahul Publications
UNIT-
IV PROGRAMMING ySING ASP .NEJ
Output browser.
produces the following output to the
It
http//localhost:50134/Data X
6) localhost.5( 1208%
DataTable
shows data of
The DataList
ID: 10I
Name: Sachin Kumar
Email: [email protected]
ID: 102
Name: Peter
Email: [email protected]
ID: 103
Name: RavíKumar
Email: [email protected]
ID: 104
Name: Irfan
Email: ifaua esanple.com
database
Example with Rahul PubliCaliuns
ASPNET DataList
{161 }
PROGRAMMING USING ASP NET
Output
It produces the following output to the browser.
http:Jccalhct:49959 Date x
Ic caincs: 120:
ID Name |Email
101Deepak Kumar deepak'a example.com
102John johna example.com
o3subránaniunn Swamilsubramanium @example.om
044bdul Khan abdut a example.com
<th>Unit Price</h>
</tr>
<tbody>
<asp:PlaceHolderlD ="itemPlacetHolder"runat "server"/>
</tbody>
</table>
<Layoutemplate>
<ltemTemplate>
<tr>
<td> <%# Eval("ProductlD") %></td>
<td> <%# Eval("ProductName")%></td>
<td><%# Eval("UnitPrice") %></td>
</tr>
</ltemTemplate>
<AlternatingltemTemplate>
<trstyle ="background-color: #dadada;">
<td><%# Eval(ProductID")%></d>
<td><%# Eval("ProductName")%></td>
<td> <%# Eval("UnitPrice")%></td>
</tr>
</AlternatingltemTemplate>
</asp:ListView>
following figure shows:
The above ListViewwill render HTML table as
Proic D Prodact Name Utt Pice
Del luspiron 132$ Nteme 500
3
Del Sudo 15 Bue
Del Inspiron 1$$ Black 600
Del Inspiron il5 Prenin
So0
Dell \'ostro 1310 Ntene Power
Del \PS \MI30 CG
600
Nokia
{187 }
BCA YEAR VSEMESTER
User Controls
User controls behaves like miniature ASPNET pages or web forms, which could be used by rnany
other pages. These are derived from the System, Web,UL,UserControl cass. These controls have the
following characteristics:
They have an .ascx extension.
They may not contain anv <html>, <body>, or <form> tags
They have a Control directive instead of a Page directive. footer for
which will work as the we,
To understand the concept, let us create a simple user control,
pages. To create and use the user control, take the following steps:
Cheate a new web application.
Solu-tion Explorer and choose Add New Itern.
ight clhick on the project folder on the
Sclution bplorer cuto.
Solutcn 'custormcontrclderno
Cirn
Pubish..
Convert to Wed Appxion
2. Check Accessibility..
Add Refeiencc..
tng tem
Add Web ReferencG...
NewFolder
Add Servce Reference...
Add ASP.NEY Fo!der
s Componert..
Cls55... Sct as StetUp Prcect
Debug
file:
Add the following code to the
<table>
<ir>
<td
<tdalion="center" >Copyright 02010 TutorialPoints Ltd.
</tr <tr>
</d
<tdalian="center"> Localion: Hyderabad, A.P
</tr></table > nstance o!
control to your web page, you must add the Register directive and an
To add the user following code shows the content file:
Control to the page. The
the user
188
Rahul Publications
.NET
PROGAAMMING USING ASP
Untitled Page
<tide
< head>
<body>
<iomid="forml runat="server">
<div>
<asp:LabellD="Label1'runat="server"Text-"Welcome to ASPNet Tutorials "></asp:Label>
<br ><br/>
<asp:ButtonlD="Buttonl"runat="serveronclick="Button1 Click"Text="Copyright Info">
<div>
<Tiooter:footerlD="footer1"runat="server"/>
<íomn>
< body></htmnl>
the pages ci your
When executed, the page shows the footer and this control could be used in all
website.
|Copyright Info
Copyright 2010 TutorialPoints Ltd.
Location: Hyderabad,-AP T
129