Вы находитесь на странице: 1из 7

Developing Web Applications Using ASP.

NET
Objectives

In this session, you will learn to:


Create and retrieve database connections by using the
Web.Config file
Access relational data by using the SqlDataSource control and
data controls
Access XML data by using the XmlDataSource control and
data controls
Access objects as data by using the ObjectDataSource control
and data controls

Ver. 1.0

Slide 1 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data

Problem Statement:
You are a developer in the Adventure Works organization, a
fictitious bicycle manufacturer. You have been asked to assist
in the development of the Business-to-Consumer (B2C) Web
application and a related Business-to-Employee (B2E) extranet
portal.
Decisions on the design of the application have already been
made. You have been asked to carry out a number of specific
tasks in order to implement various elements of this design.

Ver. 1.0

Slide 2 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data (Contd.)

As part of the first phase of the B2C development, you have


been asked to implement prototypes of pages that display and
manipulate data from the AdventureWorks database.You have
also been asked to implement prototypes of pages that display
and manipulate data from custom object data sources and
XML data from the TrailReport Web service.

Ver. 1.0

Slide 3 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data (Contd.)

Solution:
To solve this problem, you need to perform following tasks:
1. Create and Retrieve Database Connections
a. Add a connection string for the AdventureWorks database to the
Web.Config file.
b. Programmatically retrieve the connection to the AdventureWorks
database.
c. Programmatically open the connection and verify that it is open.
d. Test the database connectivity.

Ver. 1.0

Slide 4 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data (Contd.)

2. Access Data by Using SqlDataSource Controls and Data Controls


a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
k.

Ver. 1.0

Add a SqlDataSource control to the Products page.


Set connection properties for the SqlDataSource control.
Bind a DropDownList control to the SqlDataSource control.
Add and configure a Subcategories GridView control with an associated
SqlDataSource control.
Define the columns for the gvwSubcategories control.
Add and configure a Products GridView control and associated
SqlDataSource control.
Define columns and templates for the gvwProduct GridView control.
Add and configure a Product Details DetailsView control and associated
SqlDataSource control.
Add a DataList control to the ProductDetails.aspx page.
Add an SqlDataSourceControl to the page.
Run and test the Web application.

Slide 5 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data (Contd.)

3. Access Objects as Data with ObjectDataSource Controls


a.
b.
c.
d.
e.
f.
g.
h.

Ver. 1.0

Review the data-access code in the business object.


Configure an ObjectDataSource control for business-data access.
Add and configure a FormView control.
Define the EmptyDataTemplate element for the FormView control.
Define the ItemTemplate element for the FormView control.
Define the InsertItemTemplate element for the FormView control.
Add code to the Inserting event of the FormView control.
Run and test the Web application.

Slide 6 of 7

Developing Web Applications Using ASP.NET


Demo: Accessing and Displaying Data (Contd.)

4. Access XML Data by Using XmlDataSource Controls


a.
b.
c.
d.
e.

Ver. 1.0

Add an XmlDataSource object to the TrailReport.aspx page.


Add and configure a TreeView control for the TrailReport.aspx page.
Add code to an event procedure for the TreeView control.
Add code for the Page_Load event of the TrailReport.aspx page.
Test the XML data handling of the Web application.

Slide 7 of 7

Вам также может понравиться