Ads 468x60px

Thursday, July 28, 2011

Oracle/PLSQL: Data Types


Oracle/PLSQL: Data Types


The following is a list of datatypes available in Oracle.

Character Datatypes

Data Type
Syntax
Oracle 9i
Oracle 10g
Oracle 11g
Explanation
(if applicable)
char(size)
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Where size is the number of characters to store. Fixed-length strings. Space padded.
nchar(size)
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Where size is the number of characters to store. Fixed-length NLS string Space padded.
nvarchar2(size)
Maximum size of 4000 bytes.
Maximum size of 4000 bytes.
Maximum size of 4000 bytes.
Where size is the number of characters to store. Variable-length NLS string.
varchar2(size)
Maximum size of 4000 bytes.
Maximum size of 4000 bytes.
Maximum size of 4000 bytes.
Where size is the number of characters to store. Variable-length string.
long
Maximum size of 2GB.
Maximum size of 2GB.
Maximum size of 2GB.
Variable-length strings. (backward compatible)
raw
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Maximum size of 2000 bytes.
Variable-length binary strings
long raw
Maximum size of 2GB.
Maximum size of 2GB.
Maximum size of 2GB.
Variable-length binary strings. (backward compatible)

Numeric Data types

Data Type
Syntax
Oracle 9i
Oracle 10g
Oracle 11g
Explanation
(if applicable)
number(p,s)
Precision can range from 1 to 38.
Scale can range from -84 to 127.
Precision can range from 1 to 38.
Scale can range from -84 to 127.
Precision can range from 1 to 38.
Scale can range from -84 to 127.
Where p is the precision and s is the scale.
For example, number(7,2) is a number that has 5 digits before the decimal and 2 digits after the decimal.
numeric(p,s)
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Where p is the precision and s is the scale.
For example, numeric(7,2) is a number that has 5 digits before the decimal and 2 digits after the decimal.
float




dec(p,s)
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Where p is the precision and s is the scale.
For example, dec(3,1) is a number that has 2 digits before the decimal and 1 digit after the decimal.
decimal(p,s)
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Precision can range from 1 to 38.
Where p is the precision and s is the scale.
For example, decimal(3,1) is a number that has 2 digits before the decimal and 1 digit after the decimal.
integer




int




smallint




real




double precision





Date/Time Data types

Data Type
Syntax
Oracle 9i
Oracle 10g
Oracle 11g
Explanation
(if applicable)
date
A date between Jan 1, 4712 BC and Dec 31, 9999 AD.
A date between Jan 1, 4712 BC and Dec 31, 9999 AD.
A date between Jan 1, 4712 BC and Dec 31, 9999 AD.

timestamp (fractional seconds precision)
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
Includes year, month, day, hour, minute, and seconds.
For example:
timestamp(6)
timestamp (fractional seconds precision) with time zone
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
Includes year, month, day, hour, minute, and seconds; with a time zone displacement value.
For example:
timestamp(5) with time zone
timestamp (fractional seconds precision) with local time zone
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
fractional seconds precision must be a number between 0 and 9. (default is 6)
Includes year, month, day, hour, minute, and seconds; with a time zone expressed as the session time zone.
For example:
timestamp(4) with local time zone
interval year
(year precision)
to month
year precision is the number of digits in the year. (default is 2)
year precision is the number of digits in the year. (default is 2)
year precision is the number of digits in the year. (default is 2)
Time period stored in years and months.
For example:
interval year(4) to month
interval day
(day precision)
to second (fractional seconds precision)
day precision must be a number between 0 and 9. (default is 2)
fractional seconds precision must be a number between 0 and 9. (default is 6)
day precision must be a number between 0 and 9. (default is 2)
fractional seconds precision must be a number between 0 and 9. (default is 6)
day precision must be a number between 0 and 9. (default is 2)
fractional seconds precision must be a number between 0 and 9. (default is 6)
Time period stored in days, hours, minutes, and seconds.
For example:
interval day(2) to second(6)

Large Object (LOB) Datatypes

Data Type
Syntax
Oracle 9i
Oracle 10g
Oracle 11g
Explanation
(if applicable)
bfile
Maximum file size of 4GB.
Maximum file size of 232-1 bytes.
Maximum file size of 264-1 bytes.
File locators that point to a binary file on the server file system (outside the database).
blob
Store up to 4GB of binary data.
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage).
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage).
Stores unstructured binary large objects.
clob
Store up to 4GB of character data.
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage) of character data.
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage) of character data.
Stores single-byte and multi-byte character data.
nclob
Store up to 4GB of character text data.
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage) of character text data.
Store up to (4 gigabytes -1) * (the value of the CHUNK parameter of LOB storage) of character text data.
Stores unicode data.

Rowid Datatypes

Data Type
Syntax
Oracle 9i
Oracle 10g
Oracle 11g
Explanation
(if applicable)
Rowed
The format of the rowid is: BBBBBBB.RRRR.FFFFF
Where BBBBBBB is the block in the database file;
RRRR is the row in the block;
FFFFF is the database file.
The format of the rowid is: BBBBBBB.RRRR.FFFFF
Where BBBBBBB is the block in the database file;
RRRR is the row in the block;
FFFFF is the database file.
The format of the rowid is: BBBBBBB.RRRR.FFFFF
Where BBBBBBB is the block in the database file;
RRRR is the row in the block;
FFFFF is the database file.
Fixed-length binary data. Every record in the database has a physical address or rowid.
urowid(size)



Universal rowid.
Where size is optional.







Oracle/PLSQL: Literals


A literal is the same as a constant. We'll cover three types of literals - text literals, integer literals, and number literals
Text literals are always surrounded by single quotes ('). For example:
'Hewlett Packard'
'28-MAY-03'

Integer literals can be up to 38 digits. Integer literals can be either positive numbers or negative numbers. If you do not specify a sign, then a positive number is assumed. Here are some examples of valid integer literals:
23
+23
-23

Number literals can be up to 38 digits. Number literals can be either positive or negative numbers. If you do not specify a sign, then a positive number is assumed. Here are some examples of valid number literals:
25
+25
-25
25e-04
25.607


Oracle/PLSQL: Declaring Variables


The syntax for declaring variables is:
variable_name [CONSTANT] datatype [NOT NULL] [:= | DEFAULT initial_value]

For example:
Declaring a variable:
LDescription varchar2(40);
           
Declaring a constant:
LTotal CONSTANT numeric(8,1) := 8363934.1;

Declaring a variable with an initial value (not a constant):
LType varchar2(10) := 'Example';


Oracle/PLSQL: IS NULL


In PLSQL to check if a value is null, you must use the "IS NULL" syntax.
For example,
IF Lvalue IS NULL then
    ...
END IF;
If Lvalue contains a null value, the "IF" expression will evaluate to TRUE.

You can also use "IS NULL" in an SQL statement. For example:
select * from suppliers
where supplier_name IS NULL;
This will return all records from the suppliers table where the supplier_name contains a null value.

To learn how to check for a value that is not null, click here.


Oracle/PLSQL: IS NOT NULL


In PLSQL to check if a value is not null, you must use the "IS NOT NULL" syntax.
For example,
IF Lvalue IS NOT NULL then
    ...
END IF;
If Lvalue does not contain a null value, the "IF" expression will evaluate to TRUE.

You can also use "IS NOT NULL" in an SQL statement. For example:
select * from suppliers
where supplier_name IS NOT NULL;
This will return all records from the suppliers table where the supplier_name does not contain a null value.

Web Systems Models


Web Systems Models
Historically, the World Wide Web has functioned simply for information delivery. People have used it to gather information about a world of topics for which millions of Web sites have provided a portal. More recently, though, the Web has become something more than an electronic library of information. It has become a communications, information, and transactional platform through which many economic, social, political, educational, and cultural activities are enjoined.

Information Delivery Model
When a Web site functions as an information delivery system Web development activities are fairly simple and straight-forward. First, information content is entered into a document that will eventually become a Web page. This content is surrounded by special layout and formatting codes written in the HyperText Markup Language to control its structure and appearance in a Web browser. Then the document is saved to a Web server computer to await public access. Users access the document by entering its Web address in their browsers. This address, known as the URL or Uniform Resource Locator, specifies the site where the page is stored and its directory location on the Web server. The server, in turn, retrieves the page and sends it to the browser, which interpretes the HTML code and renders the document on the computer screen.
There are certain consequences of basing Web access on an information delivery model and in following the traditional Web authoring process. In the first place, the information content of the Web page tends to get fixed or frozen into place. It becomes embedded in and closely linked with the HTML formatting codes that surround it. Thus, it becomes difficult to make changes to the content without rewriting and reediting its presentation formats. So, it becomes troublesome to keep pages up to date, especially if the content changes routinely.
At the same time, Web page authors often need to be familiar with HTML coding. Even when using visual tools the author may need to tinker with the code to get pages to look as they should. Also it may become necessary for a Web "expert" to work closely with the content provider, offering the technical support needed to maintain the pages. Except for the simplest of pages it can get real messy maintaining a Web site over time.
There are also limited ways for the user to interact with traditional Web pages. The user often serves as a passive reader of the content, with the Web server acting as a simple electronic "page turner" for the reader. Thus, Web sites built around the information delivery model risk becoming static, passive repositories of out-dated information. Web pages risk become historical archives rather than timely, responsive sources of accurate, up-to-the-minute information.

Information Processing Model
To overcome this static, passive use of the Web the need is to begin viewing the Web not just as a simple information delivery system but as a full-featured information processing system. This change of viewpoint means that the Web itself and its comprising sites and pages need to be viewed as mechanisms to perform the full complement of input, processing, output, and storage activities required to delivery dynamic, active content -- in short, to provide the basic functionalities of an information processing system.


. Functions of an information processing system.
In an information processing model the four basic input, processing, output, and storage functions have specific meanings.
·         The input function permits users to interact with the system, requesting processing options, controlling information accesss, and specifying delivery methods; plus, the user can become the source of the data which the system processes and which it maintains in its repositories of stored information.
·         The processing function refers to the data manipulation activities and the processing logic needed to carry out the work of the system. The term implies that the system can be "programmed" to perform the arithmetic and logical operations necessary to manipulate input data and to produce output information.
·         The output function delivers the results of processing to the user in a correct, timely, and appropriately formatted fashion.
·         The storage function ensures the currency and integrity of processed information, maintaining it over the long term and permitting it to be added to, changed, or deleted in systematic fashion. In the final analysis, stored information becomes the primary content of Web pages, reflecting the most current and accurate information appearing on those page.
This last point is the most important. Unlike the tradition view, Web page content is not entered and edited on the Web page itself. Web page content is maintained apart from the Web page that displays it, stored in external files, databases, and documents that are integrated with the page in real-time, at the exact moment the page is accessed. Thus, the page always reflects the most current, live information maintained as part of the on-going data maintenance activities of the individual or organization. It is for this reason that Web pages and Web sites are termed data driven. Web page content is driven by the content of external data stores that is integrated with the page when it is accessed.
In adopting an information processing model you can begin applying Web technologies to the creation of Web sites that are truly dynamic, interactive, and up to date. Web sites can be produced wherein information content is always up-to-the-minute current, personalized to the needs of the user, and automatically changed in response to user requests or when the information itself changes. Web sites can be produced wherein the user can interact with its pages, adding to or changing information in the system or revising display formats to their preferences. An added benefit is that such sites can be created without the recurring need to manually rewrite or reformat the pages. The pages themselves change dynamically to reflect changing information or changing user preferences.
Assigning Functions to Components
Returning to the notion of a three-tier, client/server system, take a look at how the hardware components, software components, and processing functions relate to one another from an information processing perspective. Recall that the hardware components in a three-tier environment consist of a Web client computer (the desktop PC), the Web server computer, and the database or media server. Each of these three hardware components run corresponding software. Now, it is easy to map information processing functions across these three hardware/software tiers as shown in Figure 1.3.

 Functions of an information processing system mapped to a three-tier client/server system.

All input and output functions fall mainly to the Web client machine. User interface activities such as data entry, data validation, processing control, and output formatting are performed on the Web client, often without interaction with other system components.
The main information processing activities fall to the Web server, sometimes called the Web application server. Here is where the arithmetic and logical routines are programmed to carry out the main processing tasks -- the application logic or business logic -- of the system.
Finally, data storage and access functions take place on the database server. This data access component handles information storage and retrieval necessary for application server processing to take place. It also permits long-term maintenance of stored information through file and database additions, changes, and deletions.
As you can see in the illustration, system functions are "farmed out" to the various separate components, although they all work together in an integrated systems of activities. The basic idea is that specialty components perform the specialized work for which they are best designed. It is also true that system functions are not "place bound." That is, input, processing, output, and storage activities can take place wherever the components are located. They can be encapsulated within a single machine on a single desktop, delegated across two or more machines within a department or company, or widely scattered to the far reaches of the globe. In all of these cases the technologies and techniques used are virtually identical, making it a fairly routine matter to develop Web applications for whatever physical or geographic environment the developer encounters.

 Web Systems Models

Web Applications Development


Web Applications Development
Viewing the Web as a three-tier, client/server information processing system has important implications for developing Web applications. The "Web page author" of old becomes the "Web system developer" of today. No longer is it sufficient to pack your tool kit with a WYSIWYG editor and skeletal HTML skills. You need to become widely versed in broader know-how. Shown at the bottom of the expanded three-tier diagram in Figure 1.4 are some of the skills and tools needed to design and program Web-based systems that service information processing activities.

Web development skills needed for creating Web-based three-tier client/server applications.

System Input and Output
Since the user interface function takes place through a Web browser running on the PC client, you can use development tools that program the browser to perform output formatting, data entry, and data validation tasks, among others. For these purposes you need knowledge of markup languages such as XHTML and CSS (Cascading Style Sheets) to structure and present system input and output. Of increasing importance are markup language extensions such as DHTML (Dynamic HTML) for user interactions with the Web page and XML (eXtensible Markup Language) for representing data structures that are delivered by the server for processing on the browser. Also, the primary programming language for the browser is JavaScript, which is used to manipulate markup languages and data structures to perform browser processing tasks.
System Processing
On the Web server side you need to be able to write applications to perform the main processing activities of the system. Server languages such as Visual Basic and C# (C sharp) are used to code these routines. One the one hand, these languages function as full-features programming languages to code the arithmetic and logical details of processing; on the other hand, they call upon built-in server processing components to perform the main or ancillary work of the system. The Microsoft .NET technologies, implemented as ASP (Active Server Pages).NET, is one such collection of processing components. Through this set of software objects the Web programmer can perform virtually any processing task without having to code elaborate sets of detailed instructions. Of course, the energetic programmer can code Web applications in conventional languages such as C++, Java, and the like, or can code specialized software components callable through Visual Basic or C# for application of their processing functions to the task at hand.

It is more accurate to think of server languages such as Visual Basic and C# as scripting languages rather than programming languages. Their use is in tying together prebuilt components from, say, the .NET framework, moreso than in writing intricate processing details. This is becoming the nature of Web applications development, producing a logical roadmap of processing tasks which are implemented as preprogrammed, black-box components adaptable to specific processing needs. A Web script, rather than being a computer program, is a processing control structures to call upon available software components to perform the work of the system.
Database Management

On the database server side, languages such as SQL (Structured Query Language) perform the data storage, maintenance, and access functions to keep information up to date and accurate for Web presentation. In addition, database programming languages are used to code command procedures, processing functions stored within databases to extract from, update, and report on their contents. Server languages call upon these SQL commands and stored procedures to perform their associated processing, saving the developer from having to code the low-level access details directly. ADO (Active-X Data Objects).NET components provide the interface between scripting languages and these data access routines in order hide the complexity of data access. Of increasing importance in data storage and electronic data interchange are XML data structures. Being able to convert between standard file and database formats to XML formats is becoming a crucial Web development skill.


Web Programming


Web Programming
As parts of an information processing, rather than information delivery, system, the client and server components of a Web-based system take on different, and expanded, roles. The PC client, the Web server, and the database server work in coordination to generate and bring information content to the computer screen.
Conventional Page Delivery
In their traditional roles the components operate pretty much as illustrated in Figure 1.5. The Web page author codes a Web document using a text editor, an HTML editor, or a visual tool to wrap information content inside HTML formatting codes to display the information in a browser. This document is then placed in a Web-accessible folder on the Web server to await access. Users enter URL addresses in their browsers to retrieve the page for viewing, with the browser interpreting the HTML formatting codes in the received document and rendering the enclosed information on their computer screens.

 Conventional Web page authoring.
From the standpoint of the Web server, there's not much going on. The server simply locates the document and passes it along to the user. As noted, the Web server is not much more than an electronic page turner for people accessing Web documents.
Modern Information Processing
When Web pages become information processors, however, the situation changes dramatically. Now, interspersed within HTML formatting codes are server scripts and other commands directing the Web server to perform processing activities. Pages include Visual Basic code to perform arithmetic and logical operations on the data to be processed; SQL directives and calls to database procedures activitate routines on the database server to retrieve or update information; possibly JavaScript routines are included to direct client processing activities when the page is returned to the browser. The Web page becomes a set of commands directing all of the hardware and software components of the Web system to perform a coordinated set of activities to generate, process, store, and deliver information to clients.


Web Programming

 Modern Web page development.

The Web server coordinates these information processing activities. When the Web page is first retrieved from the server, it is not immediately directed to the user who requested it. Instead, the page is converted by the ASP.NET processor (aspnet_eisapi.dll) into a software class. It becomes, in effect, a compiled software object, a computer program to perform input, processing, output, and storage functions. At this point server processing is carried out and any SQL queries or database procedures are passed along to the database server for retrieval of information that is embedded in the Web page prior to its return to the client. Any browser scripts coded on the page are ignored by the server and are passed along to the client for activation when the page is returned. In effect, the Web server builds a Web page based on embedded programs and directives, returning data-processed-rich content to the browser.

Components of a Web Page
A Web page is a coordinated series of processing tasks directed to the Web server, the database server, and the Web client, all wrapped inside HTML codes to structure and format the output. The Web page outline in Figure 1.7 gives you a sense of the various kinds of processing and formatting components that can appear on a Web page.


 Components of a Web page.
Web pages are not so much "written" as they are "programmed." A page must be designed not only with a sense of presentation style but also with sensibilities about the various component parts to be orchestrated to generate its information content. The page is, fundamentally, a piece of software. As such, it must be designed and executed with the same precision and logic as any other computer program.
Although the coded Web page is a collection of client- and server-side processing components, the final page returned to the user's browser is an HTML document only. This is a key point. Server scripts and data access methods appearing in the original document are not part of the returned page. Only the processing results and HTML code are visible. The server has executed the scripts and inserted the output results inside the HTML code. The programs have been replaced by their output. The resulting page is no different from one on which you might have hard coded the output information. The only difference is that the server does the typing for you.
Since the returned page is pure HTML surrounding embedded content this means that virtually any browser can display the results. No special software is required by the client. This also means that user's cannot "reverse engineer" the resulting Web page to determine your original code; thus, security is maintained over server processing. The user is not aware of the script logic that generates the results nor of any business rules implemented in the code.
There's just a lot of stuff going on with a Web page, but it's not that difficult to sort it all out. With a little experience you should be able to integrate HTML code, CSS styles, JavaScript routines, server-based Visual Basic code, SQL commands, and .NET components into an orchestrated whole, directing all of the hardware, software, and data components of the system to produce a Web page to carry out the work of the enterprise.


ASP.NET Environment


ASP.NET Environment
The Web development environment described in these tutorials is based on ASP.NET technologies. ASP.NET is Microsoft's programming framework that enables the development of Web applications and services. Part of the .NET Platform, it is an easy and scalable way to build, deploy, and run Web applications that can target any browser or Web-aware device. In fact, one of the motivating factors behind the development of the .NET platform is the increasing use of the Internet in communicating among all sorts of devices, from standard desktop browsers through various hand-held, portable, and yet-to-be-invented devices.

ASP.NET is the fastest-growing Web development environment in use today. It powers many of the high-performance commerical Web sites, including Dell Computer, Merrill Lynch, the London Stock Exchange, NASDAQ, JetBlue Airways, USA Today, Home Shopping Network, Weight Watchers, Bank One, and Century 21. In addition, thousands of smaller private companies and public organizations continue to adopt ASP.NET as a powerful and convenient solution to wide-ranging Web processing needs. It is also a personal Web development environment. Many Web hosting services support ASP.NET technologies for personal Web sites. It can even be run on stand-alone desktop or laptop PCs with Windows XP Professional installed.

Programming Environment
ASP.NET has a rich set of software objects to work with in an object-oriented and compiled programming environment. Much of the functionality takes place in the background with details hidden from view of, and usually hidden from concern by, the programmer. All built-in software objects have easy-to-use programming interfaces permitting you to perform elaborate or complex processing with simple and straight-forward code.
Under ASP.NET 2.0 the programming environment takes on the feel of declarative programming rather than conventional logical programming. That is, programs, or scripts, are descriptions of what processing to perform moreso than how to perform it. Traditional programming requires exacting, detailed instructions on the sequence of processing steps a computer performs to generate its output. Under ASP.NET 2.0 these processing steps are largely encapsulated within available software objects. The programming task becomes one of selecting appropriate objects and requesting their properties and methods to return expected results. The details about how this processing takes place is of little concern.

It is for this reason that "programming" become "scripting" under ASP.NET. The programmer works with a higher-level set of instructions to carry out processing. Detailed programming logic is replaced by requests for services. The programmer simply declares what processing is needed; ASP.NET returns the results. The hard work of programming is prepackaged inside the components that are called.

The programming environment supports more than 25 .NET languages, including built-in support for VB.NET, C#, and JScript.NET. In this tutorial all server code is implement in Visual Basic (VB.NET). As a fully object-oriented environment, the .NET Framework offers over 4500 software classes that encapsulate rich functionality like XML, data access, file upload, regular expressions, image generation, performance monitoring and logging, transactions, SMTP mail, and much more. These classes provide an extensive set of objects, properties, and methods accessible through Visual Basic to enhance your Web applications.

All of the processing functionality of VB.NET is built into ASP.NET. The primary difference in the two environments is in how input and output activities are performed. User interaction under ASP.NET is, of course, through a Web browser. Therefore, some of the form controls you may have used under VB.NET do not have ASP.NET equivalents. Still, new Web Form controls in ASP.NET that replace many of the standard HTML tags bring the two environments closer together. As both environments are further developed there is likely to be convergence of the two technologies into one. Applications development for the desktop and for the Web will be virtually indistinguishable.

Though code is compiled, ASP.NET automatically detects any code changes, dynamically compiles the files if needed, and stores the compiled results for reuse in subsequent requests. Dynamic compilation ensures that applications are up to date, and compiled execution makes them fast. There is a short delay when a page is first accessed and compiled. Subsequent accesses, though, retrieve the compiled, cached version of the page for immediate execution.

Instructional Focus and Assumptions

Web development pertains to the use of Web technologies to build client and server processing components, to integrate them as applications within intranet, internet, and extranet processing systems, and to deploy them across the Web to conduct the private and public business affairs of organizations. The skill set to accomplish these tasks range well beyond the ability to save Web pages from a word processing program, to drag and drop a simple Web site with a desktop package, or even to hard-code pages with HTML and a scattering of plug-ins.
In the final analysis, the Web developer needs insight into the operational and management processes of organizations, an understanding of how work flows produce and rely upon information flows in the production of goods and services, an ability to abstract and model these business systems around the hardware and software technologies available, and the technical skills to build Web-based systems that operationalize these models.
It is sometimes too easy to view Web development from a purely technical perspective. The wise developer, however, is a systems analyst, one who understands organizational structures, work-flow processes, and the human dynamics that make them operate. Web-based systems are, first and foremost, business processes. They exist for the purpose of effecting outcomes in the best interests of the enterprise. They do not exist as technical playgrounds for the developer. Web development, then, is a problem analysis and solution development exercise, applied within the broader context of organizational goals and the cultures that pursue them. If you do not understand the purpose and functioning of the enterprise, it is unlikely you can develop systems to support it.
Web development is also an integration exercise. The systems design task is to bring to bear collections of hardware, software, people, and procedures to carry out an activity. Thus, a systems perspective is crucial for tying all the pieces together into something functional, productive, cost-effective, and friendly. A partner skill is programming ability, at least having programming sensibilities if not language skills. At the implementation level Web development is a programming exercise, moderated somewhat as a scripting exercise in current-day practice. You should think like a programmer even if you aren't one.
Finally, Web development is a creative process. So often the work is to devise something new where nothing has existed before. Rather than following directives and well-conceived plans, your imagination might have to create those plans for the artist in you to pursue them. Controlled flights of fancy serve the Web developer well.
The Web developer, then, needs creative imagination, organizational sensibilities, and a broad skill set applied through programming logic to build applications that service the information processing needs of modern organizations. These tutorials can't provide all of that; however, they do cover a basic subset of technical tools and problem-solving skills needed to create dynamic, interactive Web sites.
On the browser side, XHTML and CSS skills are assumed; JavaScript and Dynamic HTML techniques are helpful but not necessary. Visual Basic (VB.NET) is used as the server scripting language. You should have good facility in its use, primarily in coding its decision and control structures and in calling subprograms and functions. Visual Basic is the default server language under ASP.NET, which is the assumed development environment. The tutorials discuss and illustrate ASP.NET 2.0, released early in November, 2005. Also covered are the built-in ASP.NET software objects needed to perform input, processing, output, and storage functions under direction of Visual Basic scripts. On the database side, examples are presented for Microsoft Access, and fundamental use of the SQL language is described. ADO.NET components are used for script interaction with databases.
As you can see, ASP.NET is not an isolated development environment that can be exercised in the absence of other important Web development skills. As best possible, these supporting skills are kept to a minimum in these tutorials in order to concentrate on the task at hand. Nonetheless, a professional Web developer maintains a full repertoire of Web design, layout, styling, browser scripting, server programming, and data access skills. Although you might not have had exposure to all of these technologies, you should be able to follow the instructions and begin creating your own Web-based applications.
 ASP.NET Environment

Web Development Environment


Web Development Environment
Many people are Web page "authors." Armed with a visual Web production tool such as Microsoft FrontPage, Macromedia Dreamweaver, Adobe GoLive!, and others, even a technical novice can throw together a Web site with decorated text and sparkling graphics to present all manner of personal statements on the Web. You may be one of these people, spanning the generations between toddlers and grandparents, to have one's own Web site or to have produced sites for others. It is no small trick to do so, but you are just dipping a toe into an ocean of opportunity.
Fewer people are Web site "developers." A smaller cadre possess the technical know-how and system-level sensibilities to produce sites that are truly useful, responsive, self sustaining, and intregal to the public lives they represent. More importantly, fewer people are able to create commercial-grade Web sites, those that are foundational to the operations and management of modern organizations. Here is where the action is and herein lie the know-how and skills to separate yourself from the crowded pack of Web page authors. You are soon to join these latter ranks of professional Web developers, possessing a toolkit to pursue the depths and breadths of Web technologies.

Web Page Authoring
Authoring Web pages is not a particularly difficult task now-a-days. Many standard deskop software packages come equipped with built-in features to convert word processing documents, spreadsheets, databases, and the like to coded documents that are ready for access across the Web. These and other authoring packages permit creation of Web pages with drag-and-drop ease. In most cases it is not even necessary to know or even to be aware of the special HTML (HyperText Markup Language) coding that takes place behind the scenes. It's all produced for you in documents that can be published on the Web for immediate access.
If you know the HTML language -- more recently XHTML (eXtensible HyperText Markup Language) -- then you can author your pages with a simple text editor, usually gaining a great deal more control over their structure and formatting than is possible with drag-and-drop methods. In addition, you have the ability to easily integrate HTML code, browser scripting languages, Java applets, multimedia plug-ins, and other processing features to bring a modicum of user interactively to your pages. Irrespective of the substance or sizzle of your pages, however, their purpose tends to be limited to presenting interesting or informative text and graphics for personal consumption. It is unlikely you can tackle the task of producing a commercial Web site or Web-based business system armed with HTML and a few plug-ins.

Web Development
Professional Web development goes well beyond the use of HTML markup codes and a few plug-ins and scripting techniques to make attractive and informative Web pages. It involves producing Web sites that have commercial or business value. It involves the use of special strategies, tools, and techniques to produce applications best characterized as Web-based, three-tier, client/server, information processing systems. These terms are considered in more detail below for understanding the broader-ranging purposes for which Web pages and Web sites are developed.

Information Processing Systems
Web technologies can be used not just to produce simple personal or promotional Web sites but are becoming important means to support the foundational business processes of modern organizations, that is, their underlying operational and management-support functions. The technical infrastructures to realize these purposes are roughly classified into three types of Web-based information processing systems termed intranets, internets, and extranets.
Intranets. Intranets are private, internal systems to help carry out the day-to-day information processing, management information, and work-flow activities of organizations. Web-based intranets service these standard business functions and in doing so impact basic organizational systems such as accounting and financial reporting systems, marketing and sales systems, purchasing and distribution systems, production systems, and human resource systems, among others. In time, Web-based intranets will likely become the primary technical means through which organizations function internally to carry out their business and work-flow processes.
Internets. Internets are public information systems. They include public sites that provide news, information, and entertainment; electronic commerce (e-commerce) sites to market and sell products and services; government sites to inform or service the general public; and educational sites to provide local and remote access to education and training. In all sectors of society public internets are providing goods, services, and information to the public through the World Wide Web (WWW) and its associated networks and facilities.
Extranets. Extranets are business-to-business (B2B) systems that manage electronic data interchange (EDI) between business enterprises. These systems facilitate the flow of information between organizations -- between a company and its suppliers and between the company and its distributors -- to help coordinate the sequence of purchasing, production, and distribution. Electronic data interchange helps eliminate the paper flow accompanying business transactions by using Web technologies to transfer electronic documents for processing between computers rather than between people. As Web-based systems, EDI applications eliminate the difficulties of transmitting information among different hardware and software platforms with inherently different information formats and with different protocols for exchanging information.
In short, the Web is becoming the primary technical means, the electronic highway if you will, for information production, collection, processing, and distribution in all types of organizations -- in commercial and financial enterprises, educational institutions, government agencies, health-care facilities, news and entertainment industries, and in most other formal organizations both large and small. It is the pervasive technology for developing information processing systems in all sectors of society.
Web-Based
The term "Web-based" implies that information processing systems rely on the technology of the Internet, particularly on that portion known as the World Wide Web (WWW), for implementation. That is, Web-based systems operate within a technical framework with the following characteristics.
First, systems operate across public, rather than private, data networks. They communicate over the Internet, the world-wide interconnected networks of computers that are publically accessible. This means that Web-based information systems can literally span the globe with processing activities shared among components located anywhere on Earth and beyond where Web service is available.
Second, these communications networks are based on open and public technical standards such as Ethernet architectures, TCP/IP transmission protocols, and HTTP (HyperText Transport Protocol), FTP (File Transfer Protocol), SMTP (Simple Mail Transfer Protocol), and other common application protocols. These are not private or proprietary standards but are fundamentally open and free to public use.
Third, Web-based systems use common, often-times free, software for development and delivery. Even the most complex systems can be coded with nothing more than a standard text editor and placed into production through common Web server software. This software is usually built into the server computer's operating system or can often be downloaded for free. Also, interaction with Web-based systems takes place through standard Web browsers rather than specially configured hardware and software. Of course, as Web-based systems grow and become more crucial to operations they require additional components to increase capacity, speed, and security. However, most hardware and software components are off-the-shelf varieties rather than special-made.
Thus, common, non-specialized, non-proprietary hardware and software systems provide the technical environment for developing information processing systems and for operating and managing information processing activities.

Three-tier, Client/Server Architecture
The term "client/server" pertains to the use of server-based networks to manage resource sharing and to distribute processing tasks among hardware and software components. Within Web-based client/server networks the distribution of processing tasks occurs in three tiers that correspond to the three primary hardware/software components of the system. These tiers are shown in Figure 1.1.

Figure 1-1. Hardware and software layers of a three-tier information processing system.
In Tier 1 the desktop PC client handles the user interface activities of the system; in Tier 2 the Web server handles the primary processing functions of the system; and in Tier 3 the database server, and in certain cases the media server, handles information storage and retrieval functions required by the system.
In turn, each of the three hardware components host corresponding software. The client software is a standard Web browser such as Microsoft Internet Explorer. The Web server runs a network operating system such as Windows Server 2003 with component services such as Internet Information Services (IIS) hosting World Wide Web, FTP, SMTP mail, and other Internet services. The database server runs a database management system such as SQL Server, Oracle, Access, or other popular package. In sum, separate system components perform separate processing tasks that are integrated through the Web into a complete information processing system.
Consider, for instance, your visit to an e-commerce Web site such as Amazon.com or BarnesAndNoble.com. Your Web browser is your interface with the site. In response to various "input" requests you submit as you navigate the items for sale, various "output" pages are produced. Your requests are entered into the system through Web links and form submissions; system responses produce HTML pages delivered back to your browser for display on the screen. The browser performs the input and output activities needed to interface with the site.
Behind the scenes special information processing tasks are taking place on the Web server. When you request a book search, for example, programs are run to search databases to extract matching books and to format the output for delivery to your browser. When you view your shopping cart other routines retrieve your choices and summize your purchases. When you check out special programs are run to link into the credit checking and banking systems so that appropriate accounts are debited and credited. Myriad processing tasks associated with your browsing and purchasing experience take place on Web servers, hidden from your view and scattered geographically, but crucial to your shopping experience and to formalizing the business transactions that result.
Most of the information that is captured and generated by your shopping visit is kept in large databases hosted on separate database servers. All of the book information that you see on screen is extracted from database tables. Your purchase selections are stored in database tables. Virtually every piece of information regarding the products you view and your purchase transactions are maintained in massive databases within the e-commerce system itself or in associated databases central to the accounting, purchasing, and distribution systems that surround it.
In even the smallest Web-based commercial systems this same functionality is present. The Web browser provides the user interface to the system, special processing pages handle the business transactions, and one or more databases maintain information flowing through the system. The point is that in Web-based systems of any size the three primary tiers of functionality exist. From the standpoint of the Web developer, then, the task is to build these three separate components -- the user interface, the business processing routines, and the database maintenance components -- and to integrate then into a fully functioning information processing system.


ASP.NET 2.0 Tutorial


ASP.NET 2.0 Tutorial


This tutorial is an updated and expanded version of the earlier tutorial that is more in line with the final release of ASP.NET 2.0. It includes new examples, coding approaches, and explanations. If you have been using the previous tutorial, there should be little difficulty in transitioning to these new materials.
The tutorial is designed for college-level classes in Web Development; however, it is available to anyone with an interest in learning ASP.NET 2.0 from the ground up. It is not designed as comprehensive coverage of ASP.NET 2.0. It presents features and techniques to apply this Web development framework to produce applications of a generally useful nature. It is a learning resource moreso than a reference source.
It assumes familiarity with XHTML, Cascading Style Sheets, and the fundamentals of Web page design. It also requires basic programming skill. Although emphasis is on the Visual Basic language, those with know-how in other languages can adapt to the small amount of syntax required. Users should know the rudiments of database design and the Structured Query Language (SQL) as they apply to Microsoft Access databases. All examples run under the ASP.NET 2.0 framework. They run remotely under Windows Server 2003 or locally under Windows XP Professional. Outputs display properly under current versions of Microsoft Internet Explorer with JavaScript and cookies enabled.

How to control menu in Asp.Net? | How to Create Menu in Asp.net?


How to control menu in Asp.Net? | How to Create Menu in Asp.net?

<asp:Menu> Control
Navigation between pages of a Web site is conventionally set up with standard <a> anchor tags linked to the various pages. Often, this set of tags is enclosed inside a menu section on a page and duplicated across all pages that shares these navigational links. Of course, when using master pages, this set of links can be created one time only on the master page for display on all associated content pages.
It is not unusual that Web site navigation links change over time as new pages are added to a site, old pages are removed, and other pages are shifted around. There is routine need, then, to reconfigure these links. In this sense, navigation links are no different from other content information maintained for the Web site. They represent dynamic data that change over time. As such, there is convenience in being able to maintain this information apart from the pages on which it appears. Maintaining the navigational structure of a Web site in an external data store, rather than hard coded on the page, enhances the ability to keep it up to date.
ASP.NET 2.0 introduces the <asp:Menu> control to help manage the navigational structure of a Web site. It is used to create static links, much like hard coding <a> tags; it also permits maintenance of a site's navigational links in an external file for convenience in changing the links and, effectively, changing the structure of the site.
Creating a Navigation Menu
The navigational structure of a Web site is defined with an <asp:Menu> control in the general format shown in Figure 12-6. Certain of the property settings pertain to static menu items that are always displayed; others pertain to dynamic menu items displayed in "PopOut" submenus. Also, some of the items are pertinent when hard coding menu items, and others when binding the Menu to an external data source.
<asp:Menu id="id" Runat="Server"
  DataSourceID="id"
  DisappearAfter="milliseconds"
  DynamicBottomSeparatorImageUrl="url"
  DynamicEnableDefaultPopOutImage="False|True"
  DynamicHorizontalOffset="n"
  DynamicItemFormatString="{string}"
  DynamicPopOutImageTextFormatString="{string}"
  DynamicPopOutImageUrl="url"
  DynamicTopSeparatorImageUrl="url"
  DynamicVerticalOffset="n"
  ItemWrap="False|True"
  MaximumDynamicDisplayLevels="n"
  Orientation="Horizontal|Vertical"
  ScrollDownImageUrl="url"
  ScrollDownText="string"
  ScrollUpImageUrl="url"
  ScrollUpText="string"
  StaticBottomSeparatorImageUrl="url"
  StaticDisplayLevels="n"
  StaticEnableDefaultPopOutImage="False|True"
  StaticItemFormatString="{string}"
  StaticPopOutImageTextFormatString="{string}"
  StaticPopOutImageUrl="url"
  StaticSubMenuIndent="n"
  StaticTopSeparatorImageUrl="url"
  Target="_blank|_parent|_search|_self|_top|framename"
        
    DynamicHoverStyle-property="value"...
    DynamicMenuItemStyle-property="value"...
    DynamicSelectedStyle-property="value"...
    DynamicMenuStyle-property="value"...
    StaticHoverStyle-property="value"...
   StaticMenuStyle-property="value"...
    StaticMenuItemStyle-property="value"...
    StaticSelectedStyle-property="value"...
> 
        
  <Items>
        
    <asp:MenuItem
      DataItem="field"
      DataPath="path"
      ImageUrl="url"
      NavigateUrl="url"
      PopOutImageUrl="url"
      Selectable="False|True"
      Selected="False|True"
      SeparatorImageUrl="url"
      Target="_blank|_parent|_search|_self|_top|framename"
      Text="string"
      Value="string"
      ValuePath="path"
    />
    ...
               
  </Items>
        
  <DataBindings>
 
    <asp:MenuItemBinding
      TextField="field"
      ValueField="field"
      NavigateUrlField="field"
      Target="_blank|_parent|_search|_self|_top|framename"
    />
 
  </DataBindings>
 
</asp:Menu>
Figure 12-6. General format for <asp:Menu> control.
Creating a Static Menu
A static menu is created by coding an <asp:Menu> control inside of which is a set of menu items contained inside an <Items> section. Individual menu items are identify by <asp:MenuItem> controls containing link and display information. The following example shows a simple two-level set of menu items appearing on a master page to load content pages.
Figure 12-7. Basic navigation menu.
Code for this set of basic navigation links is shown in Listing 12-5. Each menu item is defined by an <asp:MenuItem> control. To establish submenus, as in this example, <asp:MenuItem> child controls representing submenu items are nested inside their parent <asp:MenuItem> controls.
<%@ Master %>
 
<html>
<head>
  <title>Web Site</title>
</head>
 
<body>
<form Runat="Server">
 
<table border="1">
<tr>
  <td style="width:100px; vertical-align:top; background-color:#E0E0E0">
 
  <b>Menu</b><br/>
                 
  <asp:Menu id="NavigationMenu" Runat="Server"
    StaticDisplayLevels="2">
 
    <Items>
 
    <asp:MenuItem Text="Page 1" NavigateUrl="Page1.aspx">
      <asp:MenuItem Text="Page 1-1" NavigateUrl="Page1-1.aspx"/>
      <asp:MenuItem Text="Page 1-2" NavigateUrl="Page1-2.aspx"/>
    </asp:MenuItem>
    <asp:MenuItem Text="Page 2" NavigateUrl="Page2.aspx">
      <asp:MenuItem Text="Page 2-1" NavigateUrl="Page2-1.aspx"/>
      <asp:MenuItem Text="Page 2-2" NavigateUrl="Page2-2.aspx"/>
    </asp:MenuItem>
    <asp:MenuItem Text="Page 3" NavigateUrl="Page3.aspx">
      <asp:MenuItem Text="Page 3-1" NavigateUrl="Page3-1.aspx"/>
      <asp:MenuItem Text="Page 3-2" NavigateUrl="Page3-2.aspx"/>
    </asp:MenuItem>
 
    </Items>
 
  </asp:Menu>
 
  </td>
  <td style="width:400px; vertical-align:top">
    <asp:ContentPlaceHolder id="CONTENT" Runat="Server"/>
  </td>
</tr>
</table>
 
</form>
</body>
</html>
Listing 12-5. Code for a Menu control appearing on a master page.
Each MenuItem must contain a Text property to produce a clickable link; it contains a NavigateUrl property to give the absolute or relative URL of the page. By default, only the first level (level 0) of menu items is displayed. If preferred, as in this example, the number of levels to display can be set with the StaticDisplayLevels property of the Menu control. If this property is not set, PopOut menus appear as described below.
This menu appears on the master page for display on all content pages. For this reason, the NavigateURl links probably should be full URLs beginning with "http://". If, for example, the content pages appear in different folders or subfolders, then relative links would be different as various of these pages are loaded; on certain pages the links would not be relative to the particular page. If, however, all content pages are in the same directory, then relative links, as in this example, remain constant.
By default, linked pages are loaded into the same window. An alternate is to supply a Target attribute for the Menu using any of the standard values: "_blank" (new window), "_top" (main browser window), "_search" (the windows search pane), "_self" (current window), "_parent" (parent frame of the current frame in a frameset), or a frame name (in a frameset).
Using Graphic Links
You can use graphic images in place of text links. The following example employs a set of graphic buttons to replace text labels by coding the ImageUrl property rather than the Text property of <asp:MenuItem> controls.
Figure 12-8. Navigation menu using graphic images.
Coding difference between the Menu control for this application and the previous example are shown below. Additional indention of submenus takes place with the StaticSubMenuIndent property and additional vertical spacing between buttons with the VerticalPadding style for menu items.
<asp:Menu id="NavigationMenu" Runat="Server"
  StaticDisplayLevels="2"
  StaticSubMenuIndent="20"
  StaticMenuStyle-VerticalPadding="1">
 
  <Items>
 
  <asp:MenuItem ImageUrl="Page1.gif" NavigateUrl="Page1.aspx">
    <asp:MenuItem ImageUrl="Page1-1.gif" NavigateUrl="Page1-1.aspx"/>
    <asp:MenuItem ImageUrl="Page1-2.gif" NavigateUrl="Page1-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem ImageUrl="Page2.gif" NavigateUrl="Page2.aspx">
    <asp:MenuItem ImageUrl="Page2-1.gif" NavigateUrl="Page2-1.aspx"/>
    <asp:MenuItem ImageUrl="Page2-2.gif" NavigateUrl="Page2-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem ImageUrl="Page3.gif" NavigateUrl="Page3.aspx">
    <asp:MenuItem ImageUrl="Page3-1.gif" NavigateUrl="Page3-1.aspx"/>
    <asp:MenuItem ImageUrl="Page3-2.gif" NavigateUrl="Page3-2.aspx"/>
  </asp:MenuItem>
 
  </Items>
 
</asp:Menu>
Listing 12-6. Code for a Menu control using graphic images as links.
Styling a Static Menu
You can apply various stylings to menu items. In the following example, StaticSubMenuIndent gives the amount of indention of submenus, vertical padding is added between menu items with a StaticMenuStyle-VerticalPadding, and various font and color styles are applied through StaticMenuItemStyle (normal), StaticHoverStyle (mouse over), and StaticSelectedStyle (selected item) settings.
Figure 12-9. Styled navigation menu.
Code for this application is given below. Note that when any of the "hover" styles (StaticHoverStyle) are applied to visually change a menu item on a mouse-over, the <head> tag for the page must include Runat="Server".
<%@ Master %>
 
<html>
<head Runat="Server">
  <title>Web Site</title>
</head>
...
 
<asp:Menu id="NavigationMenu" Runat="Server"
  StaticDisplayLevels="2"
  Width="100"
  StaticSubMenuIndent="10"
  StaticMenuStyle-VerticalPadding="2"
  StaticMenuItemStyle-Font-Name="Verdana"
  StaticMenuItemStyle-Font-Size="9pt"
  StaticMenuItemStyle-ForeColor="#990000"
  StaticHoverStyle-BackColor="#707070"
  StaticHoverStyle-ForeColor="#FFFFFF"
  StaticSelectedStyle-Font-Bold="True"
  StaticSelectedStyle-BackColor="#FFFFFF"
  StaticSelectedStyle-ForeColor="#990000">
 
  <Items>
 
  <asp:MenuItem Text="Page 1" NavigateUrl="Page1.aspx">
    <asp:MenuItem Text="Page 1-1" NavigateUrl="Page1-1.aspx"/>
    <asp:MenuItem Text="Page 1-2" NavigateUrl="Page1-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem Text="Page 2" NavigateUrl="Page2.aspx">
    <asp:MenuItem Text="Page 2-1" NavigateUrl="Page2-1.aspx"/>
    <asp:MenuItem Text="Page 2-2" NavigateUrl="Page2-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem Text="Page 3" NavigateUrl="Page3.aspx">
    <asp:MenuItem Text="Page 3-1" NavigateUrl="Page3-1.aspx"/>
    <asp:MenuItem Text="Page 3-2" NavigateUrl="Page3-2.aspx"/>
  </asp:MenuItem>
 
  </Items>
 
</asp:Menu>
 
...
</html>
Listing 12-7. Code to style a Menu control.
Selected Styles and Master Pages
When an <asp:Menu> control appears on a master page, the "selected" styles (StaticSelectedStyle) do not work as expected. That is, menu styling to indicate a clicked link does not appear when the new content page is loaded. In the above example, selected items are displayed with a white background and bold characters. However, special scripting is needed to produce this effect. The need for this scripting is because selected styles are applied after the page loads. Since the new content page also causes reloading of the master page, prior reference to the selected menu item is no longer available. The new page "doesn't remember" which menu item was clicked on the previous page.
A script to style a selected menu item to correspond with a loaded page is shown below. This Page_Load subprogram appears on the example master page. It gets the path of the current page, extracts the .aspx file name from the path, and programmatically selects the menu item with a matching NavigateUrl property. Once this item is selected, all StaticSelectedStyle properties are automatically applied to the item.
Sub Page_Load
 
  '-- Get page name from relative path
  Dim ThisPage As String = Page.AppRelativeVirtualPath
  Dim SlashPos As Integer = InStrRev(ThisPage,"/")
  Dim PageName As String = Right(ThisPage, Len(ThisPage) - SlashPos)
 
  '-- Select menu item with matching NavigateUrl property
  Dim ParentMenu As MenuItem
  Dim ChildMenu As MenuItem
  For Each ParentMenu in NavigationMenu.Items
    If ParentMenu.NavigateUrl = PageName Then
      ParentMenu.Selected = True
    Else
      For Each ChildMenu in ParentMenu.ChildItems
        If ChildMenu.NavigateUrl = PageName Then
          ChildMenu.Selected = True
        End If
      Next
    End If
  Next
 
End Sub
Listing 12-8. Programmatically selecting a Menu item.
The relative path to a Web page is contained in that page's AppRelativeVirtualPath property. For instance, when content page Page1-1.aspx is loaded in the above example, the Page.AppRelativeVirtualPath property of this page resembles the following string,
"~/Tutorials/ASPNET2/ASPNET11/Site4/Page1-1.aspx"
giving the relative directory path to the current page. Of interest here is just the name of the page since this is the value of the NavigateUrl property of the menu item that was clicked to load this page.
This page name is extracted from the string by searching the string backwards with the Visual Basic InStrRev() method to locate the final "/" character, beyond which is the page name. Then the Visual Basic Right() method extracts this page name.
Dim ThisPage As String = Page.AppRelativeVirtualPath
Dim SlashPos As Integer = InStrRev(ThisPage,"/")
Dim PageName As String = Right(ThisPage, Len(ThisPage) - SlashPos)
Listing 12-9. Extracting a page name from a directory path.
Now it is a matter of iterating the items in the menu to locate the one which has a NavigateUrl property that matches this page name.
Dim ParentMenu As MenuItem
Dim ChildMenu As MenuItem
For Each ParentMenu in NavigationMenu.Items
  If ParentMenu.NavigateUrl = PageName Then
    ParentMenu.Selected = True
  Else
    For Each ChildMenu in ParentMenu.ChildItems
      If ChildMenu.NavigateUrl = PageName Then
        ChildMenu.Selected = True
      End If
    Next
  End If
Next
Listing 12-10. Iterating items in a Menu list.
A menu control has an Items collection of all root-level (first-level) menu items. If a menu item also has a submeum of items, these are contained in its ChildItems collection. A For Each...Next loop is used to iterate these collections. In the above example, the NavigationMenu.Items collection of root-level Items (ParentMenu) is iterated, within which these Items' collections of ChildItems (ParentMenu.ChildItems) are iterated. A test is made of each menu item to determine if has a NavigateUrl property value matching that of the page name extracted from the page path. If so, then this menu item is selected by setting its Selected="True" property. By doing so, StaticSelectedStyle settings are applied to this menu item, and the item is highlighted to match the displayed page.
PopOut Menus
When the number of StaticDisplayLevels is set to less than the number of menu levels, a PopOut submenu is displayed when the mouse is positioned over a static menu item. In the following example, StaticDisplayLevels="1" displays only the first (level-0) static menu items. Also, an arrowhead () appears next to the menu item to indicate the presence of a PopOut submenu.
Figure 12-10. Navigation menu with PopOut submenus.
PopOut submenus are styled with "dynamic," rather than "static," style settings as shown in the following <asp:Menu> code for the above example. In this case, the PopOut submenu is styled to match the static menu through its DynamicMenuStyle settings for the submenu block, its DynamicMenuItemStyle settings for individual menu items, and its DynamicHoverStyle settings for mouse-over events.
<asp:Menu id="NavigationMenu" Runat="Server"
  StaticDisplayLevels="1"
 
  StaticMenuItemStyle-VerticalPadding="2"
  StaticMenuItemStyle-Font-Name="Verdana"
  StaticMenuItemStyle-Font-Size="9pt"
  StaticMenuItemStyle-ForeColor="#990000"
  StaticHoverStyle-BackColor="#707070"
  StaticHoverStyle-ForeColor="#FFFFFF"
 
  DynamicMenuStyle-HorizontalPadding="5"
  DynamicMenuStyle-VerticalPadding="2"
  DynamicMenuStyle-BackColor="#E0E0E0"
  DynamicMenuStyle-ForeColor="#990000"
  DynamicMenuStyle-BorderWidth="1"
  DynamicMenuStyle-BorderColor="#C0C0C0"
  DynamicMenuItemStyle-VerticalPadding="2"
  DynamicMenuItemStyle-Font-Name="Verdana"
  DynamicMenuItemStyle-Font-Size="9pt"
  DynamicMenuItemStyle-ForeColor="#990000"
  DynamicHoverStyle-BackColor="#707070"
  DynamicHoverStyle-ForeColor="#FFFFFF"
> 
 
  <Items>
 
  <asp:MenuItem Text="Page 1" NavigateUrl="Page1.aspx">
    <asp:MenuItem Text="Page 1-1" NavigateUrl="Page1-1.aspx"/>
    <asp:MenuItem Text="Page 1-2" NavigateUrl="Page1-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem Text="Page 2" NavigateUrl="Page2.aspx">
    <asp:MenuItem Text="Page 2-1" NavigateUrl="Page2-1.aspx"/>
    <asp:MenuItem Text="Page 2-2" NavigateUrl="Page2-2.aspx"/>
  </asp:MenuItem>
  <asp:MenuItem Text="Page 3" NavigateUrl="Page3.aspx">
    <asp:MenuItem Text="Page 3-1" NavigateUrl="Page3-1.aspx"/>
    <asp:MenuItem Text="Page 3-2" NavigateUrl="Page3-2.aspx">
      <asp:MenuItem Text="Page 3-2-1" NavigateUrl="Page3-2-1.aspx"/>
      <asp:MenuItem Text="Page 3-2-2" NavigateUrl="Page3-2-2.aspx"/>
    </asp:MenuItem>
  </asp:MenuItem>
 
  </Items>
 
</asp:Menu>
Listing 12-11. Creating a Menu control with PopOut submenus.
The PopOut arrowhead can be suppressed on the static menu by setting StaticEnableDefaultPopOutImage to False (or DynamicEnableDefaultPopOutImage to False for a submenu), or the arrowhead can be replaced with a graphic image by coding StaticPopOutImageUrl (or DynamicPopOutImageUrl for a submenu), and providing a URL to the image.
If the PopOut menu itself has additional levels of submenus, then the same dynamic configuration and style settings are applied to any additional levels. This formatting is shown by the three levels of menu items under "Page 3" in the above example. Also, special styling for selected menu items is not applied since only the first-level items would be so styled.
Scrolling PopOut Menus
If the length of a list of menu items does not fit on the page, then the items are presented as a scrolling list. In Figure 12-11, the list of items under the "Page 1" menu displays with scrolling. (The additional items do not link to actual pages.)
Figure 12-11. A scrolling PopOut menu.
You can change the graphic images appearing at the top and bottom of a scrolling menu list by supplying their URLs in the Menu control's ScrollDownImageUrl and ScrollUpImageUrl properties. Alternate text displayed on a mouse-over of these images are given in the ScrollDownText and ScrollUpText properties.
Graphic PopOut Menus
Graphic images can be used in place of text for PopOut menus. This effect is shown below with coding of the <asp:Menu> control identical to the previous example, with ImageUrl properties replacing Text properties in the <asp:MenuItem> controls.
Figure 12-12. PopOut menus with graphic links.