Washington State University



Dynamically Adding the Values to a List Control professor took WSU students to study abroad six times – 3 times China, 1 time Thailand/Malaysia, 1 time Czech Republic/Finland/Estonia, 1 time Russia. The amount of growth and maturity that occurs is astounding. Your professor encourages you to travel abroad with WSU programs.This program again demonstrates a way to improve the interactivity of the human-computer interface (HCI). The optional tours are loaded when the program user selects the country they are interested in.Again code is moved from one button on the form to the controls that the program user is interacting with. The result is a more natural, conversational like interaction with the web page.Code:Partial Class DynamicStudyAbroad Inherits System.Web.UI.Page 'This program shows how to dynamically build the items list for a radiobutton list, based on some selections in another control. Again a more interactive web page is a more interesting and compelling web page. This program allows the program user to select a study abroad destination and one optional tour. Another program will use a different control the checkbox list and a looping mechanism to gather the multiple selections. Maybe you can learn how to use a multi-select control and then come back and change this web page to allow the program user to select more than one optional cruise? Protected Sub rblOptionalTours_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblOptionalTours.SelectedIndexChanged 'WSU offers different study abroad trios with different prices Dim decTotal As Decimal = rblDestinations.SelectedValue If rblDestinations.SelectedIndex > -1 Then decTotal += rblOptionalTours.SelectedValue txtOutPut.Text = "The program fees for the study abroad to " & rblDestinations.SelectedItem.Text & " is " & FormatCurrency(rblDestinations.SelectedValue, 0) & vbNewLine & vbNewLine & "Adding the Optional Tour " & rblOptionalTours.SelectedItem.Text & " the trip total is " & decTotal.ToString("C0") End If End Sub Protected Sub rblDestinations_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rblDestinations.SelectedIndexChanged 'the program shows a different picture and text depending on which radiobutton option is selected. WSU travel abroad locations include Spain, thailand, China, Italy, etc. Each have optional tours which we are showing here. 'Here is another good usage of select case - evaluating the item selected on a list. It is common to use a select case to perform different functionality based on a lit control's selecteditem.text and the selectedIndex (the number of the item selected) 'In the Jackets program we showed different pictures based on the items selected, here we dynamically add different list items to the second radiobutton list based on the selection made in the first radiobutton list. It is a lot of typing, but hey you can use copy/paste. Again learn the concepts and appreciate the interactivity. Another time a databased program wil be shown. Select Case rblDestinations.SelectedIndex 'here we simply put the error checking inside the select case. We could have also used a separate line for error checking above. its just a style issue. You will develop your own style of programming, hopefully which become repetitive and easier, such as handling error checking the same way each time. Could have used .selecteditem.text and tested for name of country selected. Case -1 Exit Sub Case 0 ' China was selected Image1.ImageUrl = "china.bmp" 'Look at the code that is encased in the With End With statement. The term that is next to the With statement is inserted to every line below it that starts with a period. The code can be cleaner looking if you do not repeat the same term over and over. We will use this more when the terms are two and three segments long such as With system.data.sqlclient (to access the data connectivity objects) With rblOptionalTours .Items.Clear() .Items.Add(0) .Items(0).Text = "Walk the Wall" .Items(0).Value = 75 .Items.Add(1) .Items(1).Text = "Old Peking Experience" .Items(1).Value = 125 .Items.Add(2) .Items(2).Text = "Hangpu River Boat trip" .Items(2).Value = 65 End With Case 1 'Greece was selected so change the picture and the optional tours Image1.ImageUrl = "greece.jpg" With rblOptionalTours .Items.Clear() .Items.Add(0) .Items(0).Text = "Foodie Tourism" .Items(0).Value = 275 .Items.Add(1) .Items(1).Text = "Acropolis Experience" .Items(1).Value = 125 .Items.Add(2) .Items(2).Text = "Sea Cruise" .Items(2).Value = 265 End With Case 2 'Italy was selected so change the picture and the optional tours Image1.ImageUrl = "italy.jpg" With rblOptionalTours .Items.Clear() .Items.Add(0) .Items(0).Text = "Pasta Factory" .Items(0).Value = 25 .Items.Add(1) .Items(1).Text = "3 Days in Venice" .Items(1).Value = 625 .Items.Add(2) .Items(2).Text = "Rent a Vespa Motorscooter" .Items(2).Value = 85 End With Case 3 'Thailand was selected so change the picture and the optional tours Image1.ImageUrl = "thailand.jpg" With rblOptionalTours .Items.Clear() .Items.Add(0) .Items(0).Text = "Full Moon Party" .Items(0).Value = 175 .Items.Add(1) .Items(1).Text = "Visit Old Thailand" .Items(1).Value = 65 .Items.Add(2) .Items(2).Text = "Mountain Excursion with Zip-lining" .Items(2).Value = 165 End With End Select 'now show the output by concatenating some object properties together with some terms. txtOutPut.Text = "The program fees for the study abroad to " & rblDestinations.SelectedItem.Text & " is " & FormatCurrency(rblDestinations.SelectedValue, 0) & vbNewLine & vbNewLine End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'clearing the form - setting the index of a list control to -1 deselects any other selection. Image1.ImageUrl = "Coug.jpg" rblDestinations.SelectedIndex = -1 rblOptionalTours.SelectedIndex = -1 txtOutPut.Text = Nothing End SubEnd Class ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download