Title: Mgmt 362a Bookstore Application: Middle Tier
131
- Mgmt 362a Bookstore Application Middle Tier
- Introducing Code-Behind Files and Databound Web
controls
2Objectives
- In this tutorial you will learn
- Write the functionality for the middle tier,
using Visual Basic code. - Modify code-behind files in a Web application.
- Use databound Web controls.
331.2 Changing the Class Name in Books.aspx.vb
- Code-behind files
- Contains the code corresponding to an ASPX page
- Written in a .NET language, such as Visual Basic
431.2 Changing the Class Name in Books.aspx.vb
(Cont.)
Figure 31.2 Code-behind files for the
Books.aspx and BookInformation.aspx pages in the
Solution Explorer.
531.2 Changing the Class Name in Books.aspx.vb
(Cont.)
Figure 31.3 Code-behind file for the Books.aspx.
631.2 Changing the Class Name in Books.aspx.vb
(Cont.)
- Page class
- Defines the basic functionality for an ASPX page
- Located in the System.Web.UI namespace
- Provides properties, methods and events that are
useful to creating Web-based applications
731.2 Changing the Class Name in Books.aspx.vb
(Cont.)
Figure 31.4 Changing the applications class
name.
831.2 Changing the Class Name in Books.aspx.vb
(Cont.)
Figure 31.5 Changing the Books.aspx Inherits
statement.
931.2 Defining the Click Event Handlerfor the
Books.aspx Page
- Session items
- Used for sharing values among ASPX pages
- Key-value pair
- Associates a value with a corresponding name
(key) which identifies the value. - Response object
- Inherited from class Page
- Redirect method
- Takes the URL of the page to which the client
browser redirects as an argument
1031.2 Defining the Click Event Handlerfor the
Books.aspx Page (Cont.)
Figure 31.6 informationButton_Click event
handler definition.
1131.2 Creating a Databound ListBox usingan
ObjectDataSource
- Binding data to an existing ListBox
- Black triangle in the upper-right corner
- Click Choose Data Source to open the Data Source
Configuration Wizard
1231.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.7 Creating a databound ListBox in the
GUI.
1331.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.8 Creating a new data source.
1431.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.9 Choosing a data source type.
1531.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.10 Choosing a business object.
1631.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
- Define Data Methods screen
- Specifies which method of the business object
will be used to obtain the data - GetData method
1731.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.11 Defining data methods.
1831.2 Creating a Databound ListBox usingan
ObjectDataSource (Cont.)
Figure 31.12 Finish defining Data Source for
ListBox.
1931.3 Defining the Page_Load Event Handler forthe
BookInformation.aspx Page
Figure 31.13 BookInformation class.
2031.3 Defining the Page_Load Event Handler for the
BookInformation.aspx Page (Cont.)
- Page_Load event handler
- Invoked automatically when an ASPX page is loaded
2131.3 Defining the Page_Load Event Handler for the
BookInformation.aspx Page (Cont.)
Figure 31.14 BookInformation class.
2231.3 Defining the Page_Load Event Handler for the
BookInformation.aspx Page (Cont.)
Figure 31.15 Page_Load event handler modified
to set a parameter value and open a database
connection.
2331.3 Defining the Page_Load Event Handler for the
BookInformation.aspx Page (Cont.)
Figure 31.16 Definition of the
bookListButton_Click event handler.
2431.3 Creating a Databound DetailsView Usingan
ObjectDataSource
Figure 31.17 Select ltNew Data Sourcegt in the
Choose Data Source TextBox.
2531.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
Figure 31.18 Defining the data methods.
2631.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
- Defining data parameters
- Define Parameters dialog
- Parameter Source drop-down list
- Session field textbox
2731.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
Figure 31.19 Defining the querys parameters.
2831.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
- Specifying displayed fields
- DetailsView Tasks menu
- Click Edit Fields to display the Fields dialog
- red X Button
- Removes items from the Selected fields ListBox
2931.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
Figure 31.20 Modifying the displayed fields in
the DetailsView.
3031.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
Figure 31.21 Removing displayed fields from the
DetailsView.
3131.3 Creating a Databound DetailsView Usingan
ObjectDataSource (Cont.)
Figure 31.22 Final Fields dialog.
32Finishing the Bookstore App
- When you complete Tutorial 31 that finishes the
Bookstore app and the assignment. - For Assignment 12
- turn in the snapshots of the two pages correctly
executing - and a copy of each of the code from the two code
behind the files (not necessary to turn in th
HTML)