regionalmap.aspxReturn to the Documentation page
  

functionsPage_Load
bindData
linkToMapsMenu

<%@ Page Language="VB" %>

<%@ import Namespace="System.Data" %>

<%@ import Namespace="System.Data.ODBC" %>

<script runat="server">

‘Declare a public variable [ds] of type DataSet. This variable will be used below and possibly in showMP.aspx and showregionalStats.aspx.’

public ds as new DataSet()

‘Declare a public variable [selectedMap] of type string. This variable will hold the name of the region clicked by the user from the file that called this one - the electionmaps.htm file i.e. the region clicked on the image map [uk2005.gif].’

public selectedMap as string

‘The Page_Load function runs when the page first loads on the client machine.’

‘Assign the selectedMap variable to the contents of the Querystring. This will be sent across from the file electionmaps.htm when the user either, selects a region from the listbox [picker], clicks a region on the image map [uk2005.gif] OR clicks a HyperLink at the bottom of this page.’

selectedMap = Request.QueryString("map")

‘Start a SELECT...CASE...END SELECT block which looks at what map was actually selected in the selectedMap variable.’

Select Case selectedMap

‘If the map selected was 'Eastern England'....’

Case "Eastern England"

‘Set the text property of the label named 'headerLabel' to "Eastern England".’

headerLabel.Text = "Eastern England"

‘Set the width property of the listbox named 'listBox1' to 200 pixels.’

listBox1.width = Unit.Pixel(200)

‘Set the image to be displayed in the image control named 'electionmap' to ".\maps for 2005 election\easternengland.gif"’

electionmap.ImageUrl = ".\maps for 2005 election\easternengland.gif"

‘Set the control's tooltip to "Election map for Eastern England - May 2005"’

electionmap.Tooltip = "Election map for Eastern England - May 2005"

‘Disable the hyperlink [easternengland] at the bottom of the page.’

easternengland.enabled = "false"

‘Similarly for all the other regions of the UK.’

Case "Greater London"
headerLabel.Text = "Greater London"
listBox1.width = Unit.Pixel(230)
electionmap.ImageUrl = ".\maps for 2005 election\greaterlondon.gif"
electionmap.Tooltip = "Election map for Greater London - May 2005"
greaterlondon.enabled = "false"
Case "ManchesterMerseyside"
headerLabel.Text = "Merseyside & Gr. Manchester"
listBox1.width = Unit.Pixel(200)
electionmap.ImageUrl = ".\maps for 2005 election\manchester&merseyside.gif"
electionmap.Tooltip = "Election map for Greater Manchester & Merseyside - May 2005"
manchestermerseyside.enabled = "false"
selectedMap = "Merseyside & Gr. Manchester"
Case "Northern England"
headerLabel.Text = "Northern England"
listBox1.width = Unit.Pixel(250)
electionmap.ImageUrl = ".\maps for 2005 election\northernengland.gif"
electionmap.Tooltip = "Election map for Northern England - May 2005"
northernengland.enabled = "false"
Case "Northern Ireland"
headerLabel.Text = "Northern Ireland"
listBox1.width = Unit.Pixel(180)
electionmap.ImageUrl = ".\maps for 2005 election\northernireland.gif"
electionmap.Tooltip = "Election map for Northern Ireland - May 2005"
northernireland.enabled = "false"
Case "Scotland"
headerLabel.Text = "Scotland"
listBox1.width = Unit.Pixel(270)
electionmap.ImageUrl = ".\maps for 2005 election\Scotland.gif"
electionmap.Tooltip = "Election map for Scotland - May 2005"
Scotland.enabled = "false"
Case "South Central England"
headerLabel.Text = "South Central England"
listBox1.width = Unit.Pixel(180)
electionmap.ImageUrl = ".\maps for 2005 election\southcentralengland.gif"
electionmap.Tooltip = "Election map for South Central England - May 2005"
Southcentralengland.enabled = "false"
Case "South-east England"
headerLabel.Text = "South-east England"
listBox1.width = Unit.Pixel(200)
electionmap.ImageUrl = ".\maps for 2005 election\southeastengland.gif"
electionmap.Tooltip = "Election map for South-east England - May 2005"
Southeastengland.enabled = "false"
Case "South-west England"
headerLabel.Text = "South-west England"
listBox1.width = Unit.Pixel(170)
electionmap.ImageUrl = ".\maps for 2005 election\southwestengland.gif"
electionmap.Tooltip = "Election map for South-west England - May 2005"
Southwestengland.enabled = "false"
Case "TyneWear"
headerLabel.Text = "Tyne & Wear"
listBox1.width = Unit.Pixel(250)
electionmap.ImageUrl = ".\maps for 2005 election\tyne&wear.gif"
electionmap.Tooltip = "Election map for Tyne & Wear - May 2005"
tynewear.enabled = "false"
selectedMap = "Tyne & Wear"
Case "Wales"
headerLabel.Text = "Wales"
listBox1.width = Unit.Pixel(230)
electionmap.ImageUrl = ".\maps for 2005 election\wales.gif"
electionmap.Tooltip = "Election map for Wales - May 2005"
wales.enabled = "false"
Case "West Central England"
headerLabel.Text = "West Central England"
listBox1.width = Unit.Pixel(180)
electionmap.ImageUrl = ".\maps for 2005 election\westcentralengland.gif"
electionmap.Tooltip = "Election map for West Central England - May 2005"
westcentralengland.enabled = "false"
Case "WestSouthYorkshire"
headerLabel.Text = "West & South Yorkshire"
listBox1.width = Unit.Pixel(200)
electionmap.ImageUrl = ".\maps for 2005 election\west&southyorkshire.gif"
electionmap.Tooltip = "Election map for West & South Yorkshire - May 2005"
westsouthyorkshire.enabled = "false"
selectedMap = "West & South Yorkshire"
Case "West Midlands"
headerLabel.Text = "West Midlands"
listBox1.width = Unit.Pixel(250)
electionmap.ImageUrl = ".\maps for 2005 election\westmidlands.gif"
electionmap.Tooltip = "Election map for the West Midlands - May 2005"
westmidlands.enabled = "false"

‘Ends the SELECT...CASE...END SELECT block.’

End Select

‘If the form hasn’t already been submitted then run the bindData function below.’

if not Page.IsPostBack then

bindData

end if

‘Create a Session variable named ‘picked’ which will keep track of what the user selected in the listbox [listBox1]. This session variable is given to the showMP and showregionalStats aspx files if they are called from regionalmap.aspx by the user – see more on this below.’

Session("picked") = listBox1.selectedItem.Text

‘The text on the button [showConstituency] changes to reflect the constituency chosen by the user from the listbox [listBox1].’

showConstituency.Text = "Click to see " & Session("picked")

‘The bindData function is called once when the page first loads onto the client machine.’

‘The query string MySQL selects all the constituencies which are situated in the region selected – held by the string variable [selectedMap].’

Dim MySQL as string = "Select * from fullresults where district='" & selectedMap & "' order by constituency"

Dim MyConn as New ODBCConnection(ConfigurationSettings.AppSettings("strConn"))

‘An ODBCDataAdapter object [Cmd] is declared which uses the parameters MySQL and MyConn to retrieve data from the data store.’

Dim Cmd as New ODBCDataAdapter(MySQL,MyConn)

‘The Fill method puts the retrieved data into a dataset [ds] – it was defined at the top of the code as a public variable.’

Cmd.Fill(ds,"mps")

‘The listbox [listBox1] is filled with just the constituency field from the dataset and set to the first constituency i.e. if Eastern England was selected as the region then Bedford would be displayed at the top of the control.’

listBox1.DataSource=ds

listBox1.DataTextField="constituency"

listBox1.DataValueField="constituency"

listBox1.DataBind()

listBox1.SelectedIndex = 0

‘The number of items in the listbox [listBox1] are assigned to a session variable named ‘numberofseats’. Similarly session variables hold the region and the dataset in case they are needed by showMP.aspx or showregionalStats.aspx. See the documentation for those files for more on this.’

Session("numberofseats") = listBox1.items.count

Session("subsetLabel")=headerLabel.Text

Session("subsetDataSet")=ds

‘An attribute is added to the button [showConstituency]. If the user clicks the button ‘Click to see ...’ the javascript window.open function will open a second window on the screen positioned 10 pixels in from the top left-hand corner of the screen. The showMP.aspx will appear within this window displaying the result from the constituency selected within the listbox [listBox1].’

showConstituency.Attributes.Add("onclick", "window.open('showMP.aspx',null,'left=10,top=10')")

‘Similarly clicking the button ‘Stats’ will open a second window showing the compiled regional statistics for the region currently displayed on the screen – see more in showregionalStats.aspx.’

showregionalStats.Attributes.Add("onclick", "window.open('showregionalStats.aspx',null,'width=350,height=270,left=10,top=10')")

‘Tidy up the variables before ending the function.’

Cmd.Dispose

MyConn.Close()

‘A Linkbutton web control redirects the user back to the election maps page.’

Response.Redirect("electionmaps.htm")

</script>

<html>

<head>

<link href=".\otherfiles\election2005.css" type="text/css" rel="stylesheet">

</head>

‘A listbox [listBox1], two buttons [showConstituency and showregionalStats], a linkbutton [LinkToEdit] and an Image control [electionmap] displaying a regional map, are displayed on the page. The AutoPostBack property of the listbox is set to “true” so that the text on the button [showConstituency] can change depending on which constituency has been selected by the user.’

<body bgcolor="white">

<form id="form1" runat="server">

<table width="100%">

<tr><td><H3>Election maps - <asp:Label id="headerLabel" runat="server"></asp:Label></H3></td><td align=right valign=top><asp:LinkButton id="LinkToEdit" onclick="linkToMapsMenu" runat="server" Text="Return to the Maps menu"></asp:LinkButton></td></tr>

<tr><td valign="top" colspan="2"><asp:ListBox runat="server" SelectionMode="Single" AutoPostBack="true" id="listBox1" width="200" rows="1"></asp:ListBox>&nbsp;<asp:Button runat="server" Text="Click to select a constituency" id="showConstituency"></asp:Button>&nbsp;<asp:Button runat="server" id="showregionalStats" Text="Stats"></asp:Button><br><br></td></tr>

<tr><td colspan="2" align="middle"><asp:Image id="electionmap" runat="server" BorderWidth="1"></asp:Image></td></tr>

</table>

‘A second table [mapfooter] displays hyperlinks to all the other maps, allowing easy selection without having to constantly return to the maps menu page.

The NavigateURL attribute within each HyperLink tag uses a javascript function to select another map - e.g. NavigateURL="javascript:self.location='regionalmap.aspx?map=Eastern England'". The '?map=Eastern England' part of the code is known as the QueryString and can be accessed by ASP.NET both from within this page and other pages using 'Request.QueryString("map")' - returning, in this example, 'Eastern England'. The only problem is that the '&' character cannot be part of this querystring - '?map=TyneWear' gets sent NOT '?map=Tyne & Wear' - otherwise an error will occur. See the Case "TyneWear" block of the Page_Load function above for how to work around this limitation.’

<br><br><center>

<table id="mapfooter">

<tr><td align="center"><asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Eastern England'" tooltip="Click to show Eastern England" id="easternengland">Eastern England</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Greater London'" tooltip="Click to show Greater London" id="greaterlondon">Greater London</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=ManchesterMerseyside'" tooltip="Click to show Merseyside & Manchester" id="merseysidemanchester">Merseyside & Manchester</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Northern England'" tooltip="Click to show Northern England" id="northernengland">Northern England</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Northern Ireland'" tooltip="Click to show Northern Ireland" id="northernireland">Northern Ireland</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Scotland'" tooltip="Click to show Scotland" id="scotland">Scotland</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=South Central England'" tooltip="Click to show South Central England" id="southcentralengland">South Central England</asp:HyperLink></td></tr>

<tr><td align="center"><asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=South-east England'" tooltip="Click to show South-east England" id="southeastengland">South-east England</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=South-west England'" tooltip="Click to show South-west England" id="southwestengland">South-west England</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=TyneWear'" tooltip="Click to show Tyne & Wear" id="tynewear">Tyne & Wear</asp:HyperLink> | >asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=Wales'" tooltip="Click to show Wales" id="wales">Wales</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=West Central England'" tooltip="Click to show West Central England" id="westcentralengland">West Central England</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=WestSouthYorkshire'" tooltip="Click to show West & South Yorkshire" id="westsouthyorkshire">West & South Yorkshire</asp:HyperLink> | <asp:HyperLink runat="server" NavigateURL="javascript:self.location='regionalmap.aspx?map=West Midlands'" tooltip="Click to show West Midlands" id="westmidlands">West Midlands</asp:HyperLink></td></tr>

</table>

</center>

</form>

</body>

</html>

***********************************************