Hot-Link Menu in Right-Side Column

Wal Mart Online → Store Pickup → Free Shipping

Extract Local Access Database Data

Enter the following code segment above the Page_Load Event in the Order.aspx.vb file to handle the extraction of data from the Access Database:

'Create a Product Object to hold the cell data of the Access Database
Private SelectedProduct As New Product

Private Function GetSelectedProduct() As Product
    'Create a DataView Object to hold the Access Database
    Dim ProductTable As DataView

    'Create a DataRowView Object to hold 1 Row of the Access Database
    Dim ProductRow As DataRowView

'Place entire Database into ProductTable
    ProductTable = CType(AccessDataSource1.Select(DataSourceSelectArguments.Empty), DataView)

'Remove all Rows except the row that is currently selected on the DropDownList
    ProductTable.RowFilter = "ProductID = '" & ddlProducts.SelectedValue & "'"

'ProductRow = ProductTable(0)
    ProductRow = ProductTable(0)

'Transfer the cell data into the Selected Product Object
    SelectedProduct.ProductID = ProductRow("ProductID").ToString
    SelectedProduct.Name = ProductRow("Name").ToString
    SelectedProduct.ShortDescription = ProductRow("ShortDescription").ToString
    SelectedProduct.LongDescription = ProductRow("LongDescription").ToString
    SelectedProduct.UnitPrice = CDec(ProductRow("UnitPrice"))
    SelectedProduct.ImageFile = ProductRow("ImageFile").ToString
    Return SelectedProduct
End Function

Buy from Centurion

Order Page Visual Basic Code

When a page loads in VB.NET the IsPostBack property is set as true or false. This property indicates whether the page is being loaded in response to a Client Postback in which case the property is true or whether the page being loaded is being processed by the Browser for the first time, in which case the property is set to false.

If the page is being is loaded for the first time, we will need to bind the data from the Access Database to the DropDownList (ddlProducts). The data is automatically bound by VB.NET but not until after the page completes the PageLoad process.

Enter the following code for the PageLoad function on the Order.aspx.vb page:

Protected Sub Page_Load (ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    'Bind Data if this is the first load by the Browser
    If Not IsPostBack Then
    End If

    'Get the Cell Data
    SelectedProduct = Me.GetSelectedProduct

    'Update the Label Controls
    lblName.Text = SelectedProduct.Name
    lblShortDescription.Text = SelectedProduct.ShortDescription
    lblLongDescription.Text = SelectedProduct.LongDescription
    lblUnitPrice.Text = FormatCurrency(SelectedProduct.UnitPrice)
    ProductImage.ImageUrl = "" & SelectedProduct.ImageFile
End Sub

Help Support Mr. Centurion - Donate or Visit any Sponsor

No Purchase Necessary.

Help us keep this site operational by making a donation. Any amount is greatly appreciated. OR, if you visit our sponsor, they will make a donation for you, just for visiting.

Thank you

Correct any errors and run the program. When you do, you should get the following web page:

Order.aspx page running with no postback

Figure CC-16: Order Page Running Without Postback

Well, isn't that wonderful? We still have a problem, though, if you select a different product, the page does not update. What good is that? The reason is that there is no event for the Drop Down List changed. One choice is to solve this problem the old-fashioned way, by writing an Event Handler for the Drop Down List, but, we have already written the code to display the product with the Page_Load event handler. That would also mean writing a sub to update the product display like we did for the Page_Load event handler, or... How about if we just set the AutoPostBack property to true? If we do that, the page will reload every time a different product is selected, and viola. Set the AutoPostBack to true as indicated in the diagram below:

Set Drop Down List AutoPostBack property to true

Figure CC-17: Set Drop Down List AutoPostBack Property to True

Excellent Tech Support - Centurion Approved

Run the program again, and let's see if that's all we have to do to effectively create an event handler for the Drop Down List. Change the DropDownList selection to something like severed head. When you do, it should look like the diagram below:

Drop Down List AutoPostBack Property Set to true

Figure CC-18: Drop Down List AutoPostBack Property Set to True

Just Lovely, isn't it? Think I will set one or two up on my mantle. Of course, you can too. But, if severed heads aren't your thing maybe you might want to consider something a little more mundane like a new TV, DVR or something. To get the best deals with great tech service, and free shipping if you work it right, follow the link above to:

Centurion Online → Electronics → Video Products

If you haven't spent all of your disposable income @ Centurion Online yet, you might want to save a couple of pennies for one of those Severed Heads as illustrated in Figure CC-18. To make it possible to buy those and several other ghoulish items we will need to make a Chopping Cart page, to display the items the customer has selected for purchase.

Visit Our Sponsor to Help Support Our Site - No Purchase Necessary

I see you've made it here, and didn't get distracted by that Google Ad, right above. That being the case, let's add a second page to our site:

Add New Page to Web Site

Select: Project → Add New Item as illustrated in the diagram below:

Add New Page to Website using VB.NET

Figure CC-19: Select Project → Add New Item to add new webpage

Left-Clicking on the New Item option brings up the Template Selection Dialog Box as illustrated in the diagram below:

Add Web Form Template to VB.NET Webpage

Figure CC-20: Add Web Form Template to VB.NET Webpage

Any serious developer needs a system with the necessary Horsepower to perform the countless calculations peformed by Visual Studio. In addition, an adequate size monitor is a must so you can view the neccesary documents simultaneously. In order to get the best value for your development dollar take a trip to:

Centurion Online → Computers → Desktops

In order to continue with this guide, and start the discussion on Setting the Start Page: Press the Button below:

Visit Our Sponsor to Help Support Our Site - No Purchase Necessary


Visual Basic

Introduction to VB.NET

.NET Framework

VS2008 IDE

How VB is Compiled

Start Visual Studio

Windows Form App

Save Your Work

VB OOP Programming

Visual Basic Code

Exit Code

Button Event Code

Coding Recommendations


Error List Window

Comment Syntax

Help Window

Language Essentianl

Built-In Data Types

Declare Variables

Declare Constants

Code Arithmetic Expressions

Assignment Statements

Operator Precedence

Type Casting

Math Class

String Declaration

Conversion Functions

Conversion Methods

Formatting Functions

String Formatting

Variable Scope


Nullable Types

Loop Constructs

For Next Loop

Do While Loop

Do Until Loop



Exit Do | Exit For


Nested Loops


Array Declaration

Rnd( ) Function

Listbox Control


Parallel Arrays

Key Event Args

Dynamic Arrays

Redimension Array

Set Breakpoint

Start Debugger

ReDim Preserve

MultiDimensional Arrays

DataGridView Control

Length and Sort Methods


Pad Right

Split Method

IsNumeric Function

Multiform Projects

Add Form To Project

Form Object Methods

Form Show Method

ShowDialog Method

Form Close Method

Form Accept Button

Multiform Project Example

ASP.NET Web Programming

Create Data Source

Configure Access Data Source

Add Product Class

Extract Local Database Data

Order PageLoad VB Code

Add New Web Page

Set Start Page

Display Cart Aspx Code

Display Cart Design View

Sorted List Definition

VB.NET Session State

Create CartItem Class

GetCartContents Function

Add To Cart Event Handler

Remove Cart Item Event

Clear Cart Event Handler

Can't open VisitorHistory.txt for reading