Creating the Employee Details Page


Now you need to create the page to display the employee details to the user. Add a new Web form to the project in the secure folder and call it EmployeeDetails.aspx. When you are done creating this page, it will look like the page in Figure 12-10.

click to expand
Figure 12-10: The completed Employee Details page

Note

You will not be displaying the employee photo for a simple reason—you would have to have a method to synchronize the image in the database with the image located on the Web site. Although this is obviously doable, you will not take the time to do it here.

Add the controls and set the names of the controls according to Table 12-3.

Table 12-3: The Employee Details Controls and Names

Control

ID

Label ID

DropDownList

ddlCourtesy

lblCourtesy

Textbox

txtFirstName

lblFirstName

Textbox

txtLastName

lblLastName

Textbox

txtTitle

lblTitle

Textbox

txtReportsTo

lblReportsTo

Textbox

txtBirthDate

lblBirthDate

Textbox

txtHireDate

lblHireDate

Textbox

txtHomePhone

lblHomePhone

Textbox

txtExtension

lblExtension

Textbox

txtAddress

lblAddress

Textbox

txtCity

lblCity

Textbox

txtRegion

lblRegion

Textbox

txtPostal

lblPostal

Textbox

txtCountry

lblCountry

Textbox

txtNotes

lblNotes

Note

You might be tempted to not change the label names, but in Chapter 13, "Globalizing and Localizing Your Application," you will need to be able to access these labels by name, so now is as good a time as any to set the right names.

A few of the controls require some additional properties to be set (see Table 12-4).

Table 12-4: Additional Control Property Settings

Control

Property

Value

ddlCourtesy

Items

Add "Mr.", "Ms.", "Mrs.", "Dr." and use these values as the text and value

txtAddress

TextMode

MultiLine

txtNotes

TextMode

MultiLine

OK, that is enough to get your page built. Let's hook up some data and then you will come back and update the page. As mentioned, when you hold the cursor over the Details hyperlink, it displays the URL as EmployeeDetails.aspx?ID=x where x is the ID of the employee. This is called the query string. I will not go into a lot of detail about it, but I will show you how to pull the value out of it so that you can load the complete employee record. Let's add the code in Listing 12-10 to the Page_Load event of the Employee Details page.

Listing 12-10: Employee Details Page_Load Method

start example
 Dim objService As New localhost.Service1() Dim sEmp As localhost.structEmployee Dim i As Integer Dim intID As Integer intID = Convert.ToInt32(Page.Request.QueryString.Item("ID")) objService.Credentials = System.Net.CredentialCache.DefaultCredentials sEmp = objService.GetEmployeeDetails(intID) objService = Nothing With sEmp      For i = 0 To ddlCourtesy.Items.Count - 1           If ddlCourtesy.Items(i).Text = .TitleOfCourtesy Then                ddlCourtesy.SelectedIndex = i                Exit For           End If      Next      txtFirstName.Text = .FirstName      txtLastName.Text = .LastName      txtTitle.Text = .Title      txtReportsTo.Text = .ReportsToFirstName & " " & .ReportsToLastName      txtBirthDate.Text = .BirthDate.ToShortDateString      txtHireDate.Text = .HireDate.ToShortDateString      txtHomePhone.Text = .HomePhone      txtExtension.Text = .Extension      txtAddress.Text = .Address      txtCity.Text = .City      txtRegion.Text = .Region      txtPostal.Text = .PostalCode      txtCountry.Text = .Country      txtNotes.Text = .Notes End With 
end example

The only part of this code that is new to you is this line:

 intID = Convert.ToInt32(Page.Request.QueryString.Item("ID")) 

To get at the contents of the QueryString, you have to access the Page Request object. Each item in the QueryString becomes an item in the QueryString collection that can be accessed by name or index. In this case, you only have one item that you are passing, the employee ID that you can access by "ID". At this point, you can run the application and when you click an employee's Details hyperlink, that employee's details come up in the Employee Details page.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net