- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •Additional New Features of ASP.NET 2.0
- •New developer infrastructures
- •New compilation system
- •Additions to the page framework
- •New objects for accessing data
- •New server controls
- •A New IDE for Building ASP.NET 2.0 Pages
- •The Document Window
- •Views in the Document Window
- •The tag navigator
- •Page tabs
- •Code change status notifications
- •Error notifications and assistance
- •The Toolbox
- •The Solution Explorer
- •Lost Windows
- •Other Common Visual Studio Activities
- •Creating new projects
- •Making references to other objects
- •Using smart tags
- •Saving and importing Visual Studio settings
- •Application Location Options
- •Built-in Web server
- •Web site requiring FrontPage Extensions
- •The ASP.NET Page Structure Options
- •Inline coding
- •New code-behind model
- •New Page Directives
- •New attributes
- •New directives
- •New Page Events
- •Cross-Page Posting
- •New Application Folders
- •\Code folder
- •\Themes folder
- •\Resources folder
- •Compilation
- •The New Data Source Controls
- •The SqlDataSource and GridView Controls
- •Reading data
- •Applying paging in the GridView
- •Sorting rows in the GridView control
- •Defining bound columns in the GridView control
- •Enabling the editing of rows in the GridView control
- •Deleting data from the GridView
- •Dealing with other column types in the GridView
- •Selecting which fields to display in the DetailsView control
- •Using the GridView and DetailsView together
- •Updating, inserting, and deleting rows
- •XmlDataSource Control
- •ObjectDataSource Control
- •SiteMapDataSource Control
- •DataSetDataSource Control
- •Visual Studio 2005
- •Connection Strings
- •Site Maps
- •The PathSeparator property
- •The PathDirection property
- •The ParentLevelsDisplayed property
- •The ShowToolTips property
- •Examining the parts of the TreeView control
- •Binding the TreeView control to an XML file
- •Selecting multiple options in a TreeView
- •Specifying custom icons in the TreeView control
- •Specifying lines used to connect nodes
- •Working with the TreeView control programmatically
- •Applying different styles to the Menu control
- •Menu Events
- •Binding the Menu control to an XML file
- •SiteMap Data Provider
- •SiteMapViewType
- •StartingNodeType
- •SiteMap API
- •Why Do You Need Master Pages?
- •The Basics of Master Pages
- •Coding a Master Page
- •Coding a Content Page
- •Mixing page types and languages
- •Specifying which master page to use
- •Working with the page title
- •Working with controls and properties from the master page
- •Nesting Master Pages
- •Container-Specific Master Pages
- •Event Ordering
- •Caching with Master Pages
- •Using ASP.NET 2.0 Packaged Themes
- •Applying a theme to a single ASP.NET page
- •Applying a theme to an entire application
- •Applying a theme to all applications on a server
- •Removing themes from server controls
- •Removing themes from Web pages
- •Removing themes from applications
- •Creating Your Own Themes
- •Creating the proper folder structure
- •Creating a skin
- •Including CSS files in your themes
- •Having your themes include images
- •Defining Multiple Skin Options
- •Programmatically Working with Themes
- •Themes and Custom Controls
- •Authentication
- •Authorization
- •ASP.NET 2.0 Authentication
- •Setting up your Web site for membership
- •Adding users
- •Asking for credentials
- •Working with authenticated users
- •Showing the number of users online
- •Dealing with passwords
- •ASP.NET 2.0 Authorization
- •Using the LoginView server control
- •Setting up your Web site for role management
- •Adding and retrieving application roles
- •Deleting roles
- •Adding users to roles
- •Getting all the users of a particular role
- •Getting all the roles of a particular user
- •Removing users from roles
- •Checking users in roles
- •Using the Web Site Administration Tool
- •The Personalization Model
- •Adding a simple personalization property
- •Using personalization properties
- •Adding a group of personalization properties
- •Using grouped personalization properties
- •Defining types for personalization properties
- •Using custom types
- •Providing default values
- •Making personalization properties read-only
- •Anonymous Personalization
- •Enabling anonymous identification of the end user
- •Working with anonymous identification events
- •Anonymous options for personalization properties
- •Migrating Anonymous Users
- •Personalization Providers
- •Working with the Access personalization provider
- •Working with the SQL Server personalization provider
- •Using multiple providers
- •Building Dynamic and Modular Web Sites
- •Introducing the WebPartManager control
- •Working with zone layouts
- •Understanding the WebPartZone control
- •Explaining the WebPartPageMenu control
- •Modifying zones
- •Caching in ASP.NET 1.0/1.1
- •Output caching
- •Partial page caching
- •Data caching using the Cache object
- •Cache dependencies
- •ASP.NET 2.0 unseals the CacheDependency class
- •Enabling databases for SQL Server cache invalidation
- •Enabling tables for SQL Server cache invalidation
- •Looking at SQL Server
- •Looking at the tables that are enabled
- •Disabling a table for SQL Server cache invalidation
- •Disabling a database for SQL Server cache invalidation
- •Configuring your ASP.NET Application
- •Adding more than one table to a page
- •Attaching SQL Server cache dependencies to the Request object
- •Attaching SQL Server cache dependencies to the Cache object
- •Customizing the side navigation
- •Examining the AllowReturn attribute
- •Working with the StepType attribute
- •Adding a header to the Wizard control
- •Utilizing Wizard control events
- •Working with images from disk
- •Resizing images
- •Displaying images from streams
- •The MMC ASP.NET Snap-In
- •General
- •Custom Errors
- •Authorization
- •Authentication
- •Application
- •State Management
- •Advanced
- •ASP.NET Web Site Administration Tool
- •Home
- •Security
- •Profile
- •Application
- •Provider
- •Managing the Site Counter System
- •Generics
- •Iterators
- •Anonymous Methods
- •Operator Overloading
- •Visual Basic XML Documentation
- •New Visual Basic Keywords
- •Continue
- •Using
- •Global
- •Index
New Ways to Handle Data
ASP.NET 1.0 introduced some revolutionary ways to retrieve and manipulate data. ADO.NET (introduced in .NET 1.0) enabled you to grab data from data stores in an intuitive manner and then store the retrieved data in objects like the new DataSet object. Although the process was revolutionary, it was complicated and contained numerous possible pitfalls.
ASP.NET 2.0 introduces data source controls to bridge the gap between your data stores and the data-bound controls at your disposal. These new data controls not only enable you to retrieve data from various data stores, but they also let you easily manipulate the data (using paging, sorting, editing, and filtering) before the data is bound to an ASP.NET server control.
This chapter presents the new data source controls as well as some of the new data-bound controls that you can use to display retrieved data.
The New Data Source Controls
Before the introduction of the new data source controls, just retrieving data from a data store and displaying it in a DataGrid control was a multistep process. This is illustrated in Listing 4-1.
Listing 4-1: Binding a DataGrid control in ASP.NET 1.0/1.1 (VB only)
Dim conn As SqlConnection = New SqlConnection(“server=’localhost’; trusted_connection=true; Database=’Northwind’”)
Dim cmd As SqlCommand = New SqlCommand(“Select * From Customers”, conn) conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, “Customers”)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Chapter 4
In this example, you can see the many steps required just to retrieve the Customers table from SQL Server. First, a SqlConnection object is created to connect to SQL Server. Next, a SqlCommand object is created to pass in the command to the database from which data is to be retrieved. After the connection is opened, SqlDataAdapter is used to get the data and then fill the DataSet object that is created. After the DataSet object is in place and filled with the data from the Customers table, the DataSet object is bound to the DataGrid control with a DataBind() command.
Because ASP.NET 2.0 is backward compatible, the example shown in Listing 4-1 works just the same as it did in earlier versions of ASP.NET. Now, however, you can use one of the six new data source controls that have been introduced in ASP.NET 2.0. These controls provide a declarative way to connect to data stores and retrieve specific data. Working with the new data source controls is considerably easier than any previous methods. In most cases, you simply need a single line of code to get at the data you want and, in some cases, zero lines of code are required.
The new data source controls include some specifically designed to work with Microsoft SQL Server, Microsoft Access, and many other types of data stores. The following table details the new data source controls available in ASP.NET 2.0.
Data Source Control |
Description |
|
|
SqlDataSource |
Enables you to work with any SQL-based database, such as Microsoft |
|
SQL Server or Oracle. |
AccessDataSource |
Enables you to work with a Microsoft Access file (.mbd). |
ObjectDataSource |
Enables you to work with a business object or a Visual Studio 2005 data |
|
component. |
XmlDataSource |
Enables you to work with the information from an XML file or an XML |
|
source (for example an RSS feed). |
SiteMapDataSource |
Enables you to work with the hierarchical data represented in the site |
|
map file (.sitemap). These files and how to bind to them are discussed |
|
in Chapter 5. |
DataSetDataSource |
Enables you to work with data that is represented in a DataSet object. |
|
|
These data source controls connect to the assigned data store, retrieve the data, and perform any manipulations on the data that you specify using control attributes. The data source control does all the sorting, paging, and editing of the data. It also works with any data-bound controls such as the new GridView control to perform automatic databinding without any work on your part.
The Data-Bound Ser ver Controls
ASP.NET 2.0 provides a large collection of new data-bound server controls that can be used in conjunction with the new data source controls to display retrieved data in the browser. Although you probably recognize many controls from ASP.NET 1.0/1.1, you also meet some new server controls — such as the
76
