Professional Documents
Culture Documents
GROUP:06
GROUP:06
NET
GROUP:06
MEMBERS
SUNMITTED TO:
ABDULLA AL MAMUN 1306001
PRODIP KUMAR SARKAR
AZAD HOSSAIN -1306003
ASSISTANT PROFESSOR
UJJAL KUMAR ROY -1306004 DEPT. OF COMPUTER SCIENCE &
ENGINEERING
ABDULLA AL KAFI – 1306005
BEGUM ROKEYA
KASHI NATH BARMON -1306016
UNIVERSITY,RANGPUR
GOPAL CHANDRO ROY SWAPON -
1306040
ASP.NET Programming model
1. INTRODUCTION
ASP.NET is a Web development platform that provides services, a programming model, and
software infrastructure necessary to build enterprise-class applications. Although largely syntax
compatible with its popular predecessor Active Server Pages (ASP) ASP.NET is a revolutionary
new programming framework designed to enable the rapid development of Web applications. As
part of the Microsoft .NET platform, ASP.NET provides a component-based, extensible, and
easy-to-use way to build, deploy, and run Web applications that target any browser or mobile
device.
2. WHAT IS ASP.NET?
Like ASP and other Web development environments, ASP.NET also works on top of the HTTP
protocol and takes advantage of HTTP commands and policies to set up two-way, browser-to-
server communication and cooperation. What really differentiates ASP.NET from the plethora of
other Web development technologies is the abstract programming model it propounds, the Web
Forms model. In addition, the whole ASP.NET platform comes as a native part of the
Microsoft .NET Framework. To be sure you grasp the importance of this last point, let me
explain. ASP.NET applications are compiled pieces of code, are made of reusable and extensible
components, can be authored with first class languages (including C#, Microsoft Visual Basic
.NET, Microsoft JScript .NET, and J#), and can access the entire hierarchy of classes in the
.NET Framework.
In short, ASP.NET combines the best of all worlds. It is semantically compatible (and, to some
extent, also language compatible) with ASP. It provides the same object oriented features as JSP
applications (tag customization, compiled languages, components, extensibility, and reusability).
And as icing on the cake, ASP.NET delivers a wealth of goodies, tools, and powerful system
features that can be effectively grouped within the blanket expression tools for abstracting the
HTTP programming model. Lots of programmer-friendly classes let you develop pages using
typical desktop methods. The Web Forms model promotes an overall event-driven approach, but
it is deployed over the Web.
ASP.NET Web Forms bring the event-driven model of interaction to the Web. Implementing an
event model over the Web requires any data related to the client-side user’s activity to be
forwarded to the server for corresponding and stateful processing. The server processes the
output of client actions and triggers reactions.
An ASP.NET page is a server-side text file saved with the .aspx extension. The internal structure
of the page is extremely modular and comprises three distinct sections page directives, code, and
page layout:
Page directives. Page directives set up the environment in which the page will run,
specify how the HTTP runtime should process the page, and determine which
assumptions about the page are safe to make. Directives also let you import namespaces
to simplify coding, load assemblies not currently in the global assembly cache (GAC),
and register new controls with custom tag names and namespace prefixes.
Code section. The code section contains handlers for page and control events, plus
optional helper routines. Any source code pertinent to the page can be inserted inline or
attached to the page through a separate file.
Page layout. The page layout represents the skeleton of the page. It includes server
controls, literal text, and HTML tags. The user interface of the server controls can be
fleshed out a bit using declared attributes and control properties.
ASP.NET is the key enabling technology for all Web-related functionality provided by the .NET
Framework. The .NET Framework is made entirely of an object-oriented hierarchy of classes
that span all programming topics for Windows operating systems.
The ASP.NET runtime transforms the source code of the requested .aspx page into the living
instance of a .NET Framework class that inherits from a base class named Page. At the end of
the day, a running ASP.NET page is an object, and so it is for some of its components the server-
side controls.
Any element in an ASP.NET page that is marked with the runat attribute can be given a unique
ID, allowing you to access that element from your server-side code. Accessing items by ID is a
natural approach on the client (such as the use of Dynamic HTML pages), but it represents a
brand new scheme for server applications. Two factors make this revolutionary approach
possible:
The component-based architecture of the .NET platform, and the fact that ASP.NET is a
constituent part of that platform.
The runat attribute is what determines whether a piece of markup text is to be emitted verbatim
at render time or transformed into a stateful instance of a particular .NET class. In the latter case,
the class would make itself responsible for emitting the related markup. In an ASP.NET page, all
markup elements that have the runat attribute set to server are considered server-side controls.
The control class exposes methods and properties that let you configure the state of the
component. The control is responsible for emitting HTML code when the page is rendered to the
browser.
There are basically two families of ASP.NET server controls. They are HTML server controls
and Web server controls. System.Web.UI.HtmlControls is the namespace of HTML server
controls. System.Web.UI.WebControls groups all the Web server controls.
At the highest level of abstraction, the development of an ASP.NET application passes through
two phases—pages authoring and run-time configuration. You build the pages that form the
application, implement its user’s requirements, and then fine-tune the surrounding run-time
environment to make it serve pages effectively and securely. Let’s examine the various logical
layers to see what they contain and why they contain it.
An ASP.NET page is made of controls, free text, and markup. When the source code is
transformed into a living instance of a page class, the ASP.NET runtime makes no further
distinction between verbatim text, markup, and server controls everything is a control, including
literal text and carriage-return characters. At run time, any ASP.NET page is a mere graph of
controls.
The process model is the sequence of operations needed to process a request. When theASP.NET
runtime runs on top of IIS 5.x, the process model is based on a separate worker process named
aspnet_wp.exe. This Microsoft Win32 process receives control directly from IIS through the
hosted ASP.NET ISAPI extension. The extension is passed any request for ASP.NET resources,
and it hands them over to the worker process.
The worker process loads the common language runtime (CLR) and starts the pipeline of
managed objects that transform the original request from an HTTP payload into a full featured
page for the browser. The aspnet_isapi module and the worker process implement advanced
features such as process recycling, page output caching, memory monitoring, and thread pooling.
Each Web application runs in a distinct App Domain within the worker process. By default, the
worker process runs under a restricted, poorly privileged account named ASPNET.
There’s a well-known design pattern behind the ASP.NET provider model the strategy pattern.
The most notable feature of the strategy pattern is that it provides a way for an object, or an
entire subsystem, to expose its internals so that a client can unplug the default implementation of
a given feature and plug his own in. This is exactly what happens in ASP.NET for a number of
services, including membership, roles, state management, personalization, site navigation. The
ASP.NET provider model is the ASP.NET implementation of the strategy pattern.
The provider model is not an application feature that end users can see with their own eyes. In
itself, it doesn’t make an application show a richer content, run faster, or be more responsive.
The provider class is the component you plug into the existing framework to provide a
desired functionality the way you want.
The configuration layer supplies information used to identify and instantiate the actual
provider.
The storage layer is the physical medium where data is stored. Depending on the feature,
it can be Active Directory, an Oracle or SQL Server table, an XML file, or whatever else.
Anatomy of ASP.Net
ASP.NET pages are dynamically compiled on demand when first required in the context of a
Web application. Dynamic compilation is not specific to ASP.NET pages alone (.aspx files); it
also occurs with .NET Web Services (.asmx files), Web user controls (.ascx files), HTTP
handlers (.ashx files), and a few more ASP.NET application files such as the global.asax file. A
pipeline of run-time modules takes care of the incoming HTTP packet and makes it evolve from
a simple protocol-specific payload up to the rank of a server-side ASP.NET object—precisely,
an instance of a class derived from the system’s Page class.
Here we’ll review how an HTTP request for an .aspx resource is mapped to a page object, the
programming interface of the Page class, and how to control the generation of the markup by
handling events of the page life cycle.
Invoking a Page
Roughly speaking, an ASP.NET page contains Markup(appears in the .aspx page) and Server-side code
that the ASP.NET worker executes(appears in the .aspx page or in a separate code behind page). Now we
talk how the .aspx page is converted into a class and then compiled into an assembly. Generating an
assembly for a particular .aspx resource is a two-step process:
Firstly, the source code of the resource file is parsed and a corresponding class is created that inherits
either from Page or another class that, in turn, inherits from Page.
Second, the dynamically generated class is compiled into an assembly and cached in an ASP.NET-
specific temporary directory.
It collects all the information available about the invoked URL and the underlying resource, and then it
routes the request toward another distinct process—the ASP.NET worker process named aspnet_wp.exe.
The communication between the ISAPI extension and worker process takes place through named pipes. A
single copy of the worker process runs all the time and hosts all the active Web applications. The only
exception to this situation is when you have a Web server with multiple CPUs. In this case, you can
configure the ASP.NET runtime so that multiple worker processes run, one per each available CPU.
When a single worker process is used by all CPUs and controls all Web applications, it doesn’t
necessarily mean that no process isolation is achieved. Each Web application is, in fact, identified with its
virtual directory and belongs to a distinct application domain, commonly referred to as an AppDomain. A
new AppDomain is created within the ASP.NET worker process whenever a client addresses a virtual
directory for the first time.
Figure: The ASP.NET runtime environment according to the IIS 5.0 process model
IIS 6.0 implements its HTTP listener as a kernel-level module. As a result, all incoming requests
are first managed by such a driver—http.sys—and in kernel mode. No thirdparty code ever
interacts with the listener, and no user-mode crashes will ever affect the stability of IIS.
In the IIS 6.0 process model, ASP.NET runs even faster because no interprocess communication
between inetinfo.exe (the IIS executable) and the worker process is required. The HTTP request
is delivered directly at the worker process that hosts the CLR. Furthermore, the ASP.NET worker
process is not a special process but simply a copy of the IIS worker process.
Figure: How ASP.NET and Web applications are processed in IIS 6.0.
When a page is requested, it is loaded into the server memory, processed, and sent to the
browser. Then it is unloaded from the memory. At each of these steps, methods and events are
available, which could be overridden according to the need of the application. In other words,
you can write your own code to override the default code.
The Page class creates a hierarchical tree of all the controls on the page. All the components on
the page, except the directives, are part of this control tree. You can see the control tree by
adding trace= "true" to the page directive. We will cover page directives and tracing under
'directives' and 'event handling'.
The page life cycle phases are:
Initialization
Instantiation of the controls on the page
Restoration and maintenance of the state
Execution of the event handler codes
Page rendering
Understanding the page cycle helps in writing codes for making some specific thing happen at
any stage of the page life cycle. It also helps in writing custom controls and initializing them at
right time, populate their properties with view-state data and run control behavior code.
Following are the different stages of an ASP.NET page:
Page request - When ASP.NET gets a page request, it decides whether to parse and
compile the page, or there would be a cached version of the page; accordingly the
response is sent.
Starting of page life cycle - At this stage, the Request and Response objects are set. If
the request is an old request or post back, the Is PostBack property of the page is set to
true. The UICulture property of the page is also set.
Page initialization - At this stage, the controls on the page are assigned unique ID by
setting the UniqueID property and the themes are applied. For a new request, Postback
data is loaded and the control properties are restored to the view-state values.
Page load - At this stage, control properties are set using the view state and control state
values.
Validation - Validate method of the validation control is called and on its successful
execution, the Is Valid property of the page is set to true.
Postback event handling - If the request is a postback (old request), the related event
handler is invoked.
Page rendering - At this stage, view state for the page and all controls are saved. The
page calls the Render method for each control and the output of rendering is written to
the Output Stream class of the Response property of page.
Unload - The rendered page is sent to the client and page properties, such as Response
and Request, are unloaded and all cleanup done.
At each stage of the page life cycle, the page raises some events, which could be coded. An
event handler is basically a function or subroutine, bound to the event, using declarative
attributes such as Onclick or handle.
Following are the page life cycle events:
PreInit - PreInit is the first event in page life cycle. It checks the IsPostBack property
and determines whether the page is a postback. It sets the themes and master pages,
creates dynamic controls, and gets and sets profile property values. This event can be
handled by overloading the OnPreInit method or creating a Page_PreInit handler.
Init - Init event initializes the control property and the control tree is built. This event
can be handled by overloading the OnInit method or creating a Page_Init handler.
InitComplete - InitComplete event allows tracking of view state. All the controls turn on
view-state tracking.
LoadViewState - LoadViewState event allows loading view state information into the
controls.
LoadPostData - During this phase, the contents of all the input fields are defined with
the <form> tag are processed.
PreLoad - PreLoad occurs before the post back data is loaded in the controls. This event
can be handled by overloading the On PreLoad method or creating a Page PreLoad
handler.
Load - The Load event is raised for the page first and then recursively for all child
controls. The controls in the control tree are created. This event can be handled by
overloading the OnLoad method or creating a Page_Load handler.
LoadComplete - The loading process is completed, control event handlers are run, and
page validation takes place. This event can be handled by overloading the On Load
Complete method or creating a Page Load Complete handler
PreRender - The PreRender event occurs just before the output is rendered. By handling
this event, pages and controls can perform any updates before the output is rendered.
PreRenderComplete - As the PreRender event is recursively fired for all child controls,
this event ensures the completion of the pre-rendering phase.
SaveStateComplete - State of control on the page is saved. Personalization, control state
and view state information is saved. The HTML markup is generated. This stage can be
handled by overriding the Render method or creating a Page_Render handler.
UnLoad - The UnLoad phase is the last phase of the page life cycle. It raises the UnLoad
event for all controls recursively and lastly for the page itself. Final cleanup is done and
all resources and references, such as database connections, are freed. This event can be
handled by modifying the OnUnLoad method or creating a Page UnLoad handler.
An ASP.NET page is made up of a number of server controls along with HTML controls, text,
and images. Sensitive data from the page and the states of different controls on the page are
stored in hidden fields that form the context of that page request. ASP.NET runtime controls the
association between a page instance and its state. An ASP.NET page is an object of the Page or
inherited from it. All the controls on the pages are also objects of the related control class
inherited from a parent Control class. When a page is run, an instance of the object page is
created along with all its content controls.
An ASP.NET page is also a server side file saved with the .aspx extension. It is modular in
nature and can be divided into the following core sections:
Page Directives
Code Section
Page Layout
The page directives set up the environment for the page to run. The @Page directive defines
page-specific attributes used by ASP.NET page parser and compiler. Page directives specify how
the page should be processed, and which assumptions need to be taken about the page.
It allows importing namespaces, loading assemblies, and registering new controls with custom
tag names and namespace prefixes.
The Application directive defines application-specific attributes. It is provided at the top of the
global.aspx file. The basic syntax of Application directive is:
<%@ Application Language="C#" %>
The attributes of the Application directive are:
Attributes Description
The Assembly directive links an assembly to the page or the application at parse time. This
could appear either in the global.asax file for application-wide linking, in the page file, a user
control file for linking to a page or user control. The basic syntax of Assembly directive is:
<%@ Assembly Name ="myassembly" %>
Attributes Description
The control directive is used with the user controls and appears in the user control (.ascx) files.
The basic syntax of Control directive is:
<%@ Control Language="C#" EnableViewState="false" %>
The attributes of the Control directive are:
Attributes Description
The Implement directive indicates that the web page, master page or user control page must
implement the specified .Net framework interface. The basic syntax for implements directive is:
<%@ Implements Interface="interface_name" %>
The Master directive specifies a page file as being the mater page. The basic syntax of sample
MasterPage directive is:
The MasterType directive assigns a class name to the Master property of a page, to make it
strongly typed. The basic syntax of MasterType directive is:
<%@ MasterType attribute="value"[attribute="value" ...] %>
The OutputCache directive controls the output caching policies of a web page or a user control.
The basic syntax of OutputCache directive is:
<%@ OutputCache Duration="15" VaryByParam="None" %>
The Page directive defines the attributes specific to the page file for the page parser and the
compiler.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Trace="true" %>
The basic syntax of Page directive is:
Attributes Description
AutoEventWireup The Boolean value that enables or disables
page events that are being automatically bound
to methods; for example, Page_Load.
The PreviousPageType directive assigns a class to a page, so that the page is strongly typed.
The basic syntax for a sample PreviousPagetype directive is:
<%@ PreviousPageType attribute="value"[attribute="value" ...] %>
The Reference directive indicates that another page or user control should be compiled and
linked to the current page. The basic syntax of Reference directive is:
<%@ Reference Page ="somepage.aspx" %>
The Register derivative is used for registering the custom server controls and user controls.
The basic syntax of Register directive is:
<%@ Register Src="~/footer.ascx" TagName="footer" TagPrefix="Tfooter" %>
In particular, Template Control is the abstract class that provides both ASP.NET pages and user
controls with a base set of functionality. At the upper level of the hierarchy, we find the Control
class.
The Page class also implements the methods of the IHttpHandler interface, thus qualifying as the
handler of a particular type of HTTP requests—those for .aspx files. The key element of the
IHttpHandler interface is the ProcessRequest method, which is the method the ASP.NET
runtime calls to start the page processing that will actually serve the request.
Properties of Page Class
The properties of the Page object can be classified in three distinct groups:
Intrinsic objects properties
Worker properties
Page-specific properties
Methods of Page Class
The whole range of Page methods can be classified in a few categories based on the tasks each
method accomplishes.
Firstly, A few methods are involved with the generation of the markup for the page. It’s Called
Rendering Methods.
Secondly, others are helper methods to build the page and manage the 30/47 constituent
controls. It’s Called Controls-Related Methods.
Finally, a third group collects all the methods that have to do with client-side scripting. It’s
called Script-Related Methods.
Conclusion
ASP.NET is a complex technology built on top of a substantially simple and, fortunately, solid
and stable Web infrastructure. To provide a highly improved performance and richer
programming toolset, ASP.NET builds a desktop-like abstraction model, but it still has to rely on
HTTP and HTML to hit the target and meet end-user expectations.
In this Section we mentioned controls several times. Server controls are components that get input from
the user, process the input, and output a response as HTML. In the 46/47 next chapter, we’ll explore
various server controls, which include Web controls, HTML controls, and validation controls.
Server Controls
Controls are small building blocks of the graphical user interface, which include text boxes,
buttons, check boxes, list boxes, labels, and numerous other tools. Using these tools, the users
can enter data, make selections and indicate their preferences.
Controls are also used for structural jobs, like validation, data access, security, creating master
pages, and data manipulation.
ASP.NET uses five types of web controls, which are:
HTML controls
HTML Server controls
ASP.NET Server controls
ASP.NET Ajax Server controls
User controls and custom controls
ASP.NET server controls are the primary controls used in ASP.NET. These controls can be
grouped into the following categories:
Validation controls - These are used to validate user input and they work by running
client-side script. Validation are necessary to get the correct data as input and for
security. Validation controls provide an easy-to-use mechanism to perform a variety of
validation tasks, including testing for valid types, values within a given range, or
required fields.
Data source controls - These controls provides data binding to different data sources.
Data view controls - These are various lists and tables, which can bind to data from data
sources for displaying.
Personalization controls - These are used for personalization of a page according to the
user preferences, based on user information.
Login and security controls - These controls provide user authentication.
Master pages - These controls provide consistent layout and interface throughout the
application.
Navigation controls - These controls help in navigation. For example, menus, tree view
etc.
Rich controls - These controls implement special features. For example, AdRotator,
FileUpload, and Calendar control.
Attributes It is the collection of arbitrary attributes (for rendering only) that do not
correspond to properties on the control.
Style Gets a collection of text attributes that will be rendered as a style attribute on
the outer tag of the Web server control.
ToolTip Gets or sets the text displayed when the mouse pointer hovers over the web
server control.
Event Description
DataBinding Occurs when the DataBind method is called on a control and the control is binding to
a data source.
Disposed Occurs when a control is released from memory—the last stage in the control life
cycle.
Init Occurs when the control is initialized—the first step in the life cycle.
Load Occurs when the control is loaded into the page. Occurs after Init.
ADO.NET
ADO.NET is the data-access framework for .NET Framework. ADO stands for ActiveX Data
Object. ADO was a separate library for .net in the early days. But ADO.NET is different from it
and but ADO’s influence exits in it. To be precise, ADO.NET is the alternative to ADO in now a
days.
ADO.NET stands in between the actual data source and the application code. Through
ADO.NET, it is easy to access data sources like SQL Server, MySQL, Oracle etc, from inside
a .net backed project code base. ADO.NET separates data access from data manipulation into
discrete components that can be used separate. ADO.NET includes .NET Framework data
providers for connecting to a database, executing commands, and retrieving results.
ADO.NET has two main components for connecting, accessing and mutating data in data source.
One of the components is Data Provider and the other is Data Container. We will discuss both of
them briefly.
ADO.NET has some managed data provider which enables users to connect, modify and modify
data in data sources.
Principal Components of a .NET Data Provider:
Connection - Creates a connection with the specified data source, including Microsoft
SQL Server, Oracle, and any data source for which you can indicate either an OLE DB
provider or an ODBC driver.
Transaction - Represents a transaction to be made in the source database server.
Command - Represents a command that hits the underlying database server.
Parameter - Represents a parameter you can pass to the command object.
DataAdapter - Represents a database command that executes on the specified database
server and returns a disconnected set of records.
CommandBuilder - Represents a helper object that automatically generates commands
and parameters for a DataAdapter.
DataReader - Represents a read-only, forward-only cursor created on the underlying
database server.
These are some of the Data Providers that included in the .NET Framework:
.NET Framework For Oracle data sources. The .NET Framework Data Provider for
Data Provider for Oracle supports Oracle client software version 8.1.7 and later, and
Oracle uses the System.Data.OracleClient namespace.
EntityClient Provider Provides data access for Entity Data Model (EDM) applications.
Uses the System.Data.EntityClient namespace.
.NET Framework Provides data access for Microsoft SQL Server Compact 4.0. Uses
Data Provider for the System.Data.SqlServerCe namespace.
SQL Server Compact
4.0.
After connecting we can prepare and execute commands or statements to retrieve or manipulate
data inside the data source independent of the data source.
Data Provider also provides mechanism for transaction management, roll back etc.
ADO.NET Data Containers are in-memory counterpart of various database (data source)
constructs like table, view etc. They live in memory and once populated with data to contain
those data become completely decoupled from the corresponding data source (database). The
containers are DataSet, DataTable, DataView, DataRelation.
The dataset is a disconnected, in-memory representation of data. It can be considered as a local
copy of the relevant portions of the database. The DataSet is persisted in memory and the data in
it can be manipulated and updated independent of the database. When the use of this DataSet is
finished, changes can be made back to the central database for updating.
Others have self-explanatory names and they work in that way. But there is a middle-man here
too who works as a bridge between the data source and the in-memory objects, The Data
Adapter. Data Adapter adapts the retrieved data to the in-memory objects like DataSet or
DataTable. It handles the type conversion of data fields from data source types to the .NET
types. As DataSet or Data Table is disconnected container of data, and the adapter takes care of
filling it and submitting its data back to a particular data source.
The big difference between commands and data adapters is just in the way each one returns the
retrieved data. A query command returns a read-only, forward-only cursor the data reader.
DATA-BINDING MODEL
ADO.NET Classes
ADO.NET provides a bunch of data container classes that can be filled with any sort of data,
including results of a database query.
Collection-Based Classes
All collection classes implement the ICollection interface, which in turn implements the
IEnumerable interface. As a result, all collection classes provide a basic set of functionalities.
IList and IDictionary are two interfaces that extend ICollection, giving a more precise
characterization to the resultant collection class. ICollection provides only basic and minimal
functionality for a collection.
IList and IDictionary are two interfaces that extend ICollection, giving a more precise
characterization to the resultant collection class. ICollection provides only basic and minimal
functionality for a collection. Commonly used container classes that implement both ICollection
and IList are Array, ArrayList, and StringCollection. The IDictionary interface defines the API
that represents a collection of key/value pairs.
Data-Binding Properties:
The DataSource property lets you specify the data source object the control is linked to.
The DataSourceID property gets or sets the ID of the data source component from which the
data-bound control retrieves its data. By setting DataSourceID, you tell the control to turn to the
associated data source control for any needs regarding data—retrieval, paging, sorting, counting,
or updating.
The DataMember property gets or sets the name of the data collection to extract when data
binding to a data source:
public virtual string DataMember {get; set;}
Typically used by list controls, the DataTextField property specifies which property of a data-
bound item should be used to define the display text of the n element in a list control:
public virtual string DataTextField {get; set;}
The same happens for ListBox, CheckBoxList, and other list controls. Unlike
DataMember, the DataTextField property is necessary also in case the binding is
operated by data source components.
List Controls:
The DropDownList control enables users to select one item from a single-selection drop-down
list.
Property Description
AppendDataBoundItems- Indicates whether statically defined items should be maintained or
cleared when adding data-bound items. Not supported in ASP.NET 1.x.
AutoPostBack -Indicates whether the control should automatically post back to the server when
the user changes the selection.
The programming interface of the DropDownList control also features three properties
to configure the border of the drop-down list: BorderColor, BorderStyle, and
BorderWidth. Although the properties are correctly transformed by style properties, most
browsers won’t use them to change the appearance of the drop-down list.
Property Description
AppendDataBoundItems -Indicates whether statically defined items should be
maintained or cleared when adding data-bound items. Not
supported in ASP.NET 1.x.
AutoPostBack -Indicates whether the control should automatically post
back to the server when the user changes the selection.
CellPadding -Indicates pixels between the border and contents of the
cell.
Any list control has an Items property that contains the collection of the child items. The Items
property is implemented through the ListItemCollection class and makes each contained item
accessible via a ListItem object. The following code loops through the items stored in a
CheckBoxList control and checks the Selected property of each of them:
foreach(ListItem item in chkList.Items)
{
if (item.Selected) {
// this item is selected
}
}
The RadioButtonList control acts as the parent control for a collection of radio buttons. Each of
the child items is rendered through a RadioButton control. By design, a RadioButtonList control
can have zero or one item selected. The SelectedItem property returns the selected element as a
ListItem object. Note, though, that there is nothing to guarantee that only one item is selected at
any time. For this reason, be extremely careful when you access the SelectedItem of a
RadioButtonList control—it could be null:
if (radioButtons.SelectedValue != null)
{
// Process the selection here
...
}
Two properties make this control slightly different from other list controls—the Rows property,
which represents the number of visible rows in the control, and the SelectionMode property,
which determines whether one or multiple items can be selected. The programming interface of
the list box also contains the set of SelectedXXX properties we considered earlier. In this case,
they work as they do for the CheckBoxList control—that is, they returns the selected item with
the lowest index.
Property Description
AppendDataBoundItems -Indicates whether statically defined items should be
maintained or cleared when adding data-bound items
BulletImageUrl- Gets or sets the path to the image to use as the bullet
BulletStyle- Determines the style of the bullet
DataMember -The name of the table in the DataSource to bind
DataSource- The data source that populates the items of the list
DataSourceID- ID of the data source component to provide data
DataTextField- Name of the data source field to supply text of list items
DataTextFormatString- Formatting string used to control list items are displayed
DataValueField -Name of the data source field to supply value of a list item
DisplayMode -Determines how to display the items: plain text, link
buttons, or hyperlinks
FirstBulletNumber- Gets or sets the value that starts the numbering
Items -Gets the collection of items in the list control
Target- Indicates the target frame in case of hyperlink mode
Iterative Controls
Iterative controls are a special type of data-bound controls that supply a template-based
mechanism to create free-form user interfaces. Iterative controls take a data source, loop through
the items, and iteratively apply user-defined HTML templates to each row. This basic behavior is
common to all three ASP.NET iterators—Repeater, DataList, and DataGrid. Beyond that,
iterative controls differ from each other in terms of layout capabilities and functionality.
Property Description
AlternatingItemTemplate- Template to define how every other item is rendered.
DataMember -The name of the table in theDataSource to bind.
DataSource -The data source that populates the items of the list.
DataSourceID -ID of the data source component to provide data.Not
supported in ASP.NET 1.x.
FooterTemplate -Template to define how the footer is rendered.
HeaderTemplate -Template to define how the header is rendered.
Items -Gets a RepeaterItemCollection object—that is, a collection
of RepeaterItem objects. Each element of the collection
represents a displayed data row in the Repeater.
The DataList is a data-bound control that begins where the Repeater ends and
terminates a little before the starting point of the DataGrid control. In some
unrealistically simple cases, you could even take some code that uses a Repeater,
replace the control, and not even notice any difference. The DataList overtakes the
Repeater in several respects, mostly in the area of graphical layout. The DataList
supports directional rendering, meaning that items can flow horizontally or vertically tomatch a
specified number of columns.
The DataGrid is a column-based control and supports various types of data-bound columns,
including text columns, templated columns, and command columns. You associate the control
with a data source using the DataSource property. Just as for other data-bound controls, no data
will be physically loaded and bound until the DataBind method is called. The simplest way of
displaying a table of data using the ASP.NET grid is as follows:
<asp:DataGrid runat="server" id="grid" />
Data-Binding Expressions:
What we have examined so far is the most common form of data binding that involves list and
iterative controls and collections of data. Note that any ASP.NET controls support some minimal
form of data binding, including text boxes and labels, through the DataBind method.
Binding in Action
Data-binding expressions are particularly useful to update, in a pure declarative
manner, properties of controls that depend on other controls in the same page. For example,
suppose you have a drop-down list of colors and a label, and you want the text of the label to
reflect the selected color:
ASP.NET 2.0 supports two-way data binding—that is, the capability to bind data to controls and
submit changes back to the database. The Eval method is representative of a one-way data
binding that automates data reading but not data writing. The new Bind method can be used
whenever Eval is accepted and through a similar syntax:
<asp:TextBox Runat="server" ID="TheNotes" Text='<%# Bind("notes") %>' />
Conclusion
ASP.NET data binding has three faces—classic source-based binding as in ASP.NET 1.x, data
source controls, and data-binding expressions. Data-binding expressions serve a different
purpose from the other two binding techniques. Expressions are used declaratively and within
templated controls. They represent calculated values bindable to any property
Crystal Reports provides you with a variety of options for formatting your report, including grouping,
sorting and totaling. Crystal Reports also enables you to format the visual elements of your report, such as
fonts, character styles, borders, graphics and headers. It can connect to any RDBMS and generate report
according to user needs.
Grouping records: A well-designed report is organized so readers can easily analyze information.
Grouping similar sets of records helps readers isolate and study specific information.
Setting record order: Records ordering allows you to prioritize the appearance of specific pieces of
information in the report. Records are sorted so information can be presented in a way that is most helpful
to the reader.
Adding summaries: Crystal Reports provides many tools for analyzing information that has been drawn
from a database. A good example is the ability to summarize data.
Creating report and page headers: Report Headers and page headers can be created by placing text
objects in the header sections of the Design tab. Report headers appear at the top of the first page of the
report. Page headers appear at the head of each page.
Arranging fields: Fields can be arranged within a report by clicking and dragging.
Modifying text: Once you have placed a text object within your report, you can change text
characteristics to fit the overall appearance of your report.
Adding a template: Crystal Reports offers predefined report templates that can be used to apply a
uniform style to the visual components of your report. The template defines a report's visual
characteristics, such as font size and color, borders, and background colors or shading.