showMP.aspxReturn to the Documentation page
  

functionsPage_Load
colourRecord
putDataIn
LoadNext
LoadPrev
LoadFirst
LoadLast

<%@ Page Language="vb" %>

‘Import the namespaces below to enable a connection to an Access 2000 database’

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

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

<script runat="server">

‘Declare three integers and three string variables as public since they are used by several of the functions in this .aspx file. Also declare DataSet [ds] and DataTable objects [dTable].’

public total as integer

public index as integer

public firstID as integer

public seat as string

public changedConstituency as string

public ds as new DataSet()

public dTable as DataTable

public filterExpression as string

‘The Page_Load function displays the requested constituency. The showMP.aspx file can only be requested from a ‘Show details’ hyperlink in one of the datagrids or from an election map – clicking the ASP button displays the selected record.’

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

if Not Page.IsPostBack then

‘Assign the contents of the Session variable [subsetDataSet] to the DataSet object [ds] which has already been declared above. The Session variable has been set in the file that called showMP.aspx.’

ds = Session("subsetDataSet")

‘Assign the DataSet’s table [mps] to the DataTable object [dTable] which has also already been declared.’

dTable = ds.Tables("mps")

‘Declare dv of type DataView which takes the dTable object as a  parameter.’

dim dv as new DataView(dTable)

‘If there is a Request.QueryString which references the majority field and another that references the id field then it means that the showMP.aspx file must have been called from the Other stats menu, The most vulnerable seats menu item.’

if not (Request.QueryString("majority")) is Nothing andalso not (Request.QueryString("id")) is Nothing then

‘Set the sort method of the DataView object [dv] to sort first on the ‘majority’ field and then by the 'id' field.’

dv.sort = "majority asc, id"

‘Use the Find method of the DataView to find the unique constituency with the majority shown in the Request.QueryString together with the id. Find returns the row number of the constituency and this is assigned to the index variable’

index = dv.Find(new object(){Request.QueryString("majority"),Request.QueryString("id")})

‘Put the newly found index variable into the expression below which returns the unique ID of the record – it is stored in firstID which is then used elsewhere in the showMP.aspx file.’

firstID = ds.Tables("mps").Rows(index).Item("ID")

‘Otherwise if there is a Request.QueryString which references the swing field it means that the showMP.aspx file was called from the Other stats menu, Highest swings menu item.’

else if not (Request.QueryString("swing")) is Nothing then

‘Sort the DataView object [dv] on, first the ‘swing’ field in descending order and then, secondly, sort on the id field. The latter sort is needed because some of the constituencies have identical swings.’

dv.Sort = "swing desc, id"

‘Again, use the Find method of the DataView object [dv] with both the QueryString(‘swing’) and the QueryString(‘id’) as parameters. These multiple parameters have to be entered in as an array using the curly brackets {} and prefaced with ‘new object()’. An integer is returned which is stored in the index variable.’

index = dv.Find(new object(){Request.QueryString("swing"),Request.QueryString("id")})

‘Put the newly found index variable into the expression below which returns the unique ID of the record – it is stored in firstID which is then used elsewhere in the showMP.aspx file.’

firstID = ds.Tables("mps").Rows(index).Item("ID")

‘Otherwise if there is a Request.QueryString which references the id field it means that the showMP.aspx file was called from the other menu items on the Other stats menu which display a datagrid with a ‘Show details’ hyperlink column – i.e. partymps.aspx, countrymps.aspx, regionalmps.aspx and partygains.aspx.’

else if not (Request.QueryString("id")) is Nothing then

‘This time sort the DataView object [dv] on the ‘id’ field.’

dv.Sort = "id"

‘Again, use the Find method of the DataView object [dv] with the QueryString(‘id’) as a parameter. An integer is returned which is stored in the index variable.’

index = dv.Find(Request.QueryString("id"))

‘Assign the ‘id’ in the QueryString to the firstID variable which will be retrieved later on in the function putDataIn – see below.’

firstID = Request.QueryString("id")

‘Otherwise, if there is no Request.Querystring it means that the showMP.aspx file was called from one of the election maps by a user clicking the button ‘Click to see Bedford’ for example.’

else

‘Sort the DataView object [dv] on the ‘constituency’ field.’

dv.Sort = "constituency"

‘Use the Find method of the DataView object [dv] with the contents of the Session variable ‘picked’ as a parameter. This variable is set within the election map when the user selects a constituency from the listbox – see easternengland.aspx.’

index = dv.Find(Session("picked"))

‘Put the newly found index variable into the expression below which returns the unique ID of the record – it is stored in firstID which is then used elsewhere in the showMP.aspx file.’

firstID = ds.Tables("mps").Rows(index).Item("ID")

‘End the If…then…elseif…then…else…end if block.’

end if

‘The state bag [Me.ViewState(“total”)] holds the number of records in the DataTable [dTable] – this variable is used in the navigation panel at the bottom of the form – see the putDataIn function below.’

Me.ViewState("total") = dTable.Rows.Count

‘The state bag [Me.ViewState(“index”)] holds the row number of the selected constituency within the DataView – this variable is also used in the navigation panel at the bottom of the form.’

Me.ViewState("index") = index

‘The variable filterExpression is defined as follows: it searches the field named 'id' in the election database for the record with the id held by the variable [firstID].’

filterExpression = "id='" & firstID & "'"

‘The putDataIn function is called to populate the web form with the data from the requested id – see the function below.’

call putDataIn()

‘The colourRecord function is called to colour the background with the winning party’s colour – see more on this function below.’

call colourRecord()

‘If there is only one record in the DataTable object [dTable] and the index variable is equal to 0 then….’

if index = 0 and dTable.Rows.Count = 1 then

‘Disable all the buttons at the bottom of the webform.’

btnNext.Enabled = "false"

btnPrev.Enabled = "false"

btnFirst.Enabled = "false"

btnLast.Enabled = "false"

‘But if there is more than one record in the DataTable object [dTable] but the index variable is still set to 0 then….’

else if index = 0 and dTable.Rows.Count <> 1 then

‘Disable only the buttons named ‘btnFirst’ and ‘btnPrev’.’

btnFirst.Enabled = "false"

btnPrev.Enabled = "false"

‘But if the index variable is equal to one less than the number of records in the DataTable object [dTable] i.e. the user has selected the last record in the DataTable then….’

else if index = dTable.Rows.Count - 1 then

‘Disable only the buttons named ‘btnLast’ and ‘btnNext’.’

btnLast.Enabled = "false"

btnNext.Enabled = "false"

‘Otherwise….’

else

‘Enable only the buttons named ‘btnNext’ and ‘btnPrev’.’

btnNext.Enabled = "true"

btnPrev.Enabled = "true"

‘Ends the If…then…else if then…else…end if block.’

end if

‘Set the text property of the label control [Label3] to the contents of the Session variable named ‘subsetLabel’ This was originally set in the .aspx file that called showMP.aspx.’

Label3.Text = Session("subsetLabel")

‘Ends the ‘If Not Page.IsPostBack then’ block. If the user only clicks a naviagation button at the bottom of the form all the above code will be bypassed as the page has been sent to the server once already.’

end if

‘The colourRecord function is called by the Page_Load function and other functions below and it colours the background of the form [table1] depending on the party that won the seat i.e. a Labour seat will have a red background, a Conservative seat a blue one, etc, etc. The font colour is also adjusted to make it more readable – the cssClass property of the web form is set to the relevant style and these are defined below between the <style>…</style> tags.’

Select Case txtWinningparty.Text

Case "Labour"

table1.cssClass = "labour"

Case "Conservative"

table1.cssClass = "conservative"

Case "Liberal Democrats"

table1.cssClass = "libdem"

Case "SNP"

table1.cssClass = "snp"

Case "Plaid Cymru"

table1.cssClass = "plaidcymru"

Case "UUP"

table1.cssClass = "uup"

Case "DUP"

table1.cssClass = "dup"

Case "Sinn Fein"

table1.cssClass = "sinnfein"

Case "SDLP"

table1.cssClass = "sdlp"

Case else

table1.cssClass = "else"

End Select

‘If the number of characters in the textbox [txtResult] is greater than 20 then….’

If txtResult.Text.Length > 20 then

‘Set the cssClass property of the control to 'biggerResultwidth' - the actual width will be retrieved from the appropriate stylesheet.’

 

txtResult.cssClass = "biggerResultwidth"

‘otherwise….’

Else

‘Set the cssClass property of the control to 'smallerResultwidth'.’

txtResult.cssClass = "smallerResultwidth"

‘Ends the IF…THEN…ELSE…END IF block.’

end if

‘Go back to the calling function – Page_Load above or LoadFirst, LoadNext, LoadPrev or LoadLast below.’

return

‘The putDataIn() function is called by the Page_Load, LoadNext, LoadPrev, Load First and LoadLast functions as shown below and it populates the web form with the data for the requested MP. The function uses the variable ‘filterExpression’ within the Select method of the DataTable object [dTable] to only select that constituency from the table named 'mps’.’

‘An array of type DataRow [CurrRows()] is declared which will hold all the fields of the selected record.’ The first parameter of the Select method is a filter which is represented by a string variable [filterExpression] - the value of this will be sent by the function that calls putDataIn()'.

Dim CurrRows() as DataRow = dTable.Select( filterExpression, Nothing )

‘The text properties of the first three fields are pulled out of the array CurrRows and converted to strings with the ToString method. This avoids an error occurring if the field is empty of data, which it might be since some of the constituencies only had a few candidates standing.’

txtCountry.Text = CurrRows(0)(0).ToString

txtConstituency.Text = CurrRows(0)(1).ToString

txtRegion.Text = CurrRows(0)(2).ToString

‘Starts an IF...THEN...ELSE...END IF loop which checks to see if the contents of the Region textbox are equal to 'Merseyside & Gr. Manchester'.’

if txtRegion.Text = "Merseyside & Gr. Manchester" then

‘If it is then set the control's cssClass property to 'smallerregionFont', which will be fetched from the appropriate stylesheet.’

txtRegion.cssClass = "smallerregionFont"

‘But if it isn't....’

else

‘Set the property to 'biggerregionFont'.’

txtRegion.cssClass = "biggerregionFont"

‘Ends the IF...THEN...ELSE...END IF loop.’

end if

‘Similarly populate the specified textboxes with the appropriate data from the array CurrRows for the first three in the constituency. Note the use of the format function to make the voting figures more readable by putting in a thousands separator - format(ctype(CurrRows(0)(5).To String, integer), "#,###") - and this also requires the CType function to convert the string to an integer.’

txtFirstparty.Text = CurrRows(0)(3).ToString
txtFirst.Text = CurrRows(0)(4).ToString
txtFirstvotes.Text = format(ctype(CurrRows(0)(5).ToString,integer), "#,###")
txtSecondparty.Text = CurrRows(0)(6).ToString
txtSecond.Text = CurrRows(0)(7).ToString
txtSecondvotes.Text = format(ctype(CurrRows(0)(8).ToString,integer), "#,###")
txtThirdparty.Text = CurrRows(0)(9).ToString
txtThird.Text = CurrRows(0)(10).ToString
txtThirdvotes.Text = format(ctype(CurrRows(0)(11).ToString,integer), "#,###")

‘If there are only three candidates in the constituency, Labour, Conservative and Liberal Democrat for example, there will be NO fourthparty, etc so this row and all subsequent rows together with their associated textboxes need to be hidden from the user. Start an IF...THEN...ELSE...END IF loop that checks to see whether there is a fourth party....’

If CurrRows(0)(12).ToString = "" then

‘If there is no fourth party then make the row with id='row4' invisible.’

row4.visible = "false"

‘However if there is data within CurrRows(0)(12) then there must be a fourth candidate so....’

else

‘Make the row with id='row4' visible and populate the appropriate textboxes with the usual details - party name, candidate name and votes polled.’

row4.visible = "true"
txtFourthparty.Text = CurrRows(0)(12).ToString
txtFourth.Text = CurrRows(0)(13).ToString
txtFourthvotes.Text = format(ctype(CurrRows(0)(14).ToString,integer), "#,###")

‘Ends the IF...THEN...ELSE...END IF block.’

end if

‘Similarly for the rest of the candidates in the constituency....’

If CurrRows(0)(15).ToString = "" then
row5.visible = "false"
else
row5.visible = "true"
txtFifthparty.Text = CurrRows(0)(15).ToString
txtFifth.Text = CurrRows(0)(16).ToString
txtFifthvotes.Text = format(ctype(CurrRows(0)(17).ToString,integer), "#,###")
end if
If CurrRows(0)(18).ToString = "" then
row6.visible = "false"
else
row6.visible = "true"
txtSixthparty.Text = CurrRows(0)(18).ToString
txtSixth.Text = CurrRows(0)(19).ToString
txtSixthvotes.Text = format(ctype(CurrRows(0)(20).ToString,integer), "#,###")
end if
If CurrRows(0)(21).ToString = "" then
row7.visible = "false"
else
row7.visible = "true"
txtSeventhparty.Text = CurrRows(0)(21).ToString
txtSeventh.Text = CurrRows(0)(22).ToString
txtSeventhvotes.Text = format(ctype(CurrRows(0)(23).ToString,integer), "#,###")
end if
If CurrRows(0)(24).ToString = "" then
row8.visible = "false"
else
row8.visible = "true"
txtEighthparty.Text = CurrRows(0)(24).ToString
txtEighth.Text = CurrRows(0)(25).ToString
txtEighthvotes.Text = format(ctype(CurrRows(0)(26).ToString,integer), "#,###")
end if
If CurrRows(0)(27).ToString = "" then
row9.visible = "false"
else
row9.visible = "true"
txtNinthparty.Text = CurrRows(0)(27).ToString
txtNinth.Text = CurrRows(0)(28).ToString
txtNinthvotes.Text = format(ctype(CurrRows(0)(29).ToString,integer), "#,###")
end if
If CurrRows(0)(30).ToString = "" then
row10.visible = "false"
else
row10.visible = "true"
txtTenthparty.Text = CurrRows(0)(30).ToString
txtTenth.Text = CurrRows(0)(31).ToString
txtTenthvotes.Text = format(ctype(CurrRows(0)(32).ToString,integer), "#,###")
end if
If CurrRows(0)(33).ToString = "" then
row11.visible = "false"
else
row11.visible = "true"
txtEleventhparty.Text = CurrRows(0)(33).ToString
txtEleventh.Text = CurrRows(0)(34).ToString
txtEleventhvotes.Text = format(ctype(CurrRows(0)(35).ToString,integer), "#,###")
end if
If CurrRows(0)(36).ToString = "" then
row12.visible = "false"
else
row12.visible = "true"
txtTwelfthparty.Text = CurrRows(0)(36).ToString
txtTwelfth.Text = CurrRows(0)(37).ToString
txtTwelfthvotes.Text = format(ctype(CurrRows(0)(38).ToString,integer), "#,###")
end if
If CurrRows(0)(39).ToString = "" then
row13.visible = "false"
else
row13.visible = "true"
txtThirteenthparty.Text = CurrRows(0)(39).ToString
txtThirteenth.Text = CurrRows(0)(40).ToString
txtThirteenthvotes.Text = format(ctype(CurrRows(0)(41).ToString,integer), "#,###")
end if
If CurrRows(0)(42).ToString = "" then
row14.visible = "false"
else
row14.visible = "true"
txtFourteenthparty.Text = CurrRows(0)(42).ToString
txtFourteenth.Text = CurrRows(0)(43).ToString
txtFourteenthvotes.Text = format(ctype(CurrRows(0)(44).ToString,integer), "#,###")
end if
If CurrRows(0)(45).ToString = "" then
row15.visible = "false"
else
row15.visible = "true"
txtFifteenthparty.Text = CurrRows(0)(45).ToString
txtFifteenth.Text = CurrRows(0)(46).ToString
txtFifteenthvotes.Text = format(ctype(CurrRows(0)(47).ToString,integer), "#,###")
end if
If CurrRows(0)(48).ToString = "" then
row16.visible = "false"
else
row16.visible = "true"
txtSixteenthparty.Text = CurrRows(0)(48).ToString
txtSixteenth.Text = CurrRows(0)(49).ToString
txtSixteenthvotes.Text = format(ctype(CurrRows(0)(50).ToString,integer), "#,###")
end if

‘The last few textboxes are concerned with stats like the turnout, the swing, the majority and Label4.Text will display the number of the record within the database in the middle of the navigation panel at the bottom of the form.’

txtTurnout.Text = CurrRows(0)(51).ToString
txtSwing.Text = CurrRows(0)(52).ToString
txtSwingtoparty.Text = CurrRows(0)(53).ToString
txtresult.Text = CurrRows(0)(54).ToString
txtWinningparty.Text = CurrRows(0)(55).ToString
txtNotes.Text = CurrRows(0)(56).ToString
txtId.Text = CurrRows(0)(57).ToString
majority.Text = format(txtFirstvotes.Text - txtSecondvotes.Text, "#,###")
Label4.Text = index + 1 & " of " & Me.ViewState("total")

‘Return to the calling function - either Page_Load, LoadNext, LoadPrev, LoadFirst or LoadLast.’

return

‘The LoadNext function runs when the user clicks the Next button at the bottom of the web form. It moves the user to the next record in the subset.’

‘Assign the contents of the Session variable [subsetDataSet] to the DataSet object [ds] which was declared earlier above the Page_Load function.’

ds = Session("subsetDataSet")

‘Assign the table named ‘mps’ to the DataTable object [dTable] which was also declared earlier.’

dTable = ds.Tables("mps")

‘The record number is retrieved from the state bag and placed into the index variable. The number is then incremented by 1.’

index = Me.ViewState("index")

index += 1

‘If this index variable is less than the total number of rows in the DataTable object then….’

if index < dTable.Rows.Count then

‘Assign the name of the constituency for that row to the ‘seat’ variable.’

seat = ds.Tables("mps").Rows(index).Item("Constituency")

‘If the constituency name contains an ‘apostrophe s’ it will be replaced with  a ‘double apostrophe s’. The resulting text string is then placed into the string variable ‘changedConstituency’.’

if Instr(seat, "'s") <> 0 then

changedConstituency = Replace(seat, "'s", "''s")

‘Otherwise if the constituency doesn’t contain an ‘apostrophe s’….’

else

‘Just assign the contents of the ‘seat’ variable to the string variable ‘changedConstituency’.’

changedConstituency = seat

‘Ends the ‘If then…else…end if’ block.’

end if

‘The state bag then holds the newly incremented index variable.’

Me.ViewState("index") = index

‘The variable filterExpression is defined as follows: it searches the field named 'constituency' in the election database for the seat held in the variable [changedConstituency].’

filterExpression = "constituency='" & changedConstituency & "'"

‘Switch over to the putDataIn function which will populate the web form with the relevant constituency’s data – see function above.’

call putDataIn()

‘Similarly switch over to the colourRecord function which will change the background colour, etc of the form depending on which party won the seat – see the function above.’

call colourRecord()

‘Assign the contents of the Session variable [subsetLabel] to the text property of the label control named ‘label3’. This Session variable is set by the calling file.’

label3.Text = Session("subsetLabel")

‘Check to see if this is the last record in the database. If it is then disable the Next and Last buttons.’

if index + 1 = dTable.Rows.Count then

btnNext.Enabled = "false"

btnLast.Enabled = "false"

‘Ends the ‘If then…End if’ block.’

end if

‘Ends the first ‘If then…End if’ block in this function.’

end if

‘Ensure the First and Prev buttons are enabled.’

btnFirst.Enabled = "true"

btnPrev.Enabled = "true"

‘Similar to the LoadNext function but moves the user back one record in the dataset.’

‘Assign the contents of the Session variable [subsetDataSet] to the DataSet object [ds] which was declared earlier above the Page_Load function.’

ds = Session("subsetDataSet")

‘Assign the table named ‘mps’ to the DataTable object [dTable] which was also declared earlier.’

dTable = ds.Tables("mps")

‘The record number is retrieved from the state bag and placed into the index variable. The number is then decreased by 1.’

index = Me.ViewState("index")

index -= 1

‘If the index variable is equal to or greater than 0 then run the following code ….’

if index >= 0 then

‘Assign the name of the constituency for that row to the ‘seat’ variable.’

seat = ds.Tables("mps").Rows(index).Item("Constituency")

‘If the constituency name contains an ‘apostrophe s’ it will be replaced with  a ‘double apostrophe s’. The resulting text string is then placed into the string variable ‘changedConstituency’.’

if Instr(seat, "'s") <> 0 then

changedConstituency = Replace(seat, "'s", "''s")

‘Otherwise if the constituency doesn’t contain an ‘apostrophe s’….’

else

‘Just assign the contents of the ‘seat’ variable to the string variable ‘changedConstituency’.’

changedConstituency = seat

‘Ends the ‘If then…else…end if’ block.’

end if

‘The state bag then holds the newly decreased index variable.’

Me.ViewState("index") = index

‘The variable filterExpression is defined as follows: it searches the field named 'constituency' in the election database for the seat held in the variable [changedConstituency].’

filterExpression = "constituency='" & changedConstituency & "'"

‘Switch over to the putDataIn function which will populate the web form with the relevant constituency’s data – see function above.’

call putDataIn()

‘Similarly switch over to the colourRecord function which will change the background colour, etc of the form depending on which party won the seat – see the function above.’

call colourRecord()

‘Assign the contents of the Session variable [subsetLabel] to the text property of the label control named ‘label3’. This Session variable is set by the calling file.’

label3.Text = Session("subsetLabel")

‘Check to see if this is the first record in the database. If it is then disable the Prev and First buttons.’

if index = 0 then

btnPrev.Enabled = "false"

btnFirst.Enabled = "false"

‘Ends the ‘If then…End if’ block.’

end if

‘Ends the first ‘If then…End if’ block in this function.’

end if

‘Ensure the Last and Next buttons are enabled.’

btnLast.Enabled = "true"

btnNext.Enabled = "true"

‘The LoadFirst function runs when the user clicks the First button at the bottom of the web form. It moves the user to the first record in the subset.’

‘Assign the contents of the Session variable [subsetDataSet] to the DataSet object [ds] which was declared earlier above the Page_Load function.’

ds = Session("subsetDataSet")

‘Assign the table named ‘mps’ to the DataTable object [dTable] which was also declared earlier.’

dTable = ds.Tables("mps")

‘The index variable, which holds the record number, is set to 0 – the first record of the dataset is record 0, the second record 1, etc.’

index = 0

‘Assign the name of the constituency for the first row to the ‘seat’ variable.’

seat = ds.Tables("mps").Rows(index).Item("Constituency")

‘If the constituency name contains an ‘apostrophe s’ it will be replaced with  a ‘double apostrophe s’. The resulting text string is then placed into the string variable ‘changedConstituency’.’

if Instr(seat, "'s") <> 0 then

changedConstituency = Replace(seat, "'s", "''s")

‘Otherwise if the constituency doesn’t contain an ‘apostrophe s’….’

else

‘Just assign the contents of the ‘seat’ variable to the string variable ‘changedConstituency’.’

changedConstituency = seat

‘Ends the If then…else…end if block.’

end if

‘The state bag then holds the index variable ready to be used again by the other navigation buttons.’

Me.ViewState("index") = index

‘The variable filterExpression is defined as follows: it searches the field named 'constituency' in the election database for the seat held in the variable [changedConstituency].’

filterExpression = "constituency='" & changedConstituency & "'"

‘Switch over to the putDataIn function which will populate the web form with the relevant constituency’s data – see function above.’

call putDataIn()

‘Similarly switch over to the colourRecord function which will change the background colour, etc of the form depending on which party won the seat – see the function above.’

call colourRecord()

‘Assign the contents of the Session variable [subsetLabel] to the text property of the label control named ‘label3’. This Session variable is set by the calling file.’

label3.Text = Session("subsetLabel")

‘Ensure the First and Prev buttons are disabled and the Next and Last buttons are enabled.’

btnNext.Enabled = "true"

btnPrev.Enabled = "false"

btnLast.Enabled = "true"

btnFirst.Enabled = "false"

‘The LoadLast function runs when the user clicks the Last button at the bottom of the web form. It moves the user to the last record in the subset.’

‘Assign the contents of the Session variable [subsetDataSet] to the DataSet object [ds] which was declared earlier above in the Page_Load function.’

ds = Session("subsetDataSet")

‘Assign the table named ‘mps’ to the DataTable object [dTable] which was also declared earlier.’

dTable = ds.Tables("mps")

‘The record number is retrieved from the state bag which holds the total number of records in the datatable [see the Page_Load function above] and has one subtracted from it. It is then assigned to the index variable.’

index = Me.ViewState("total") – 1

‘Assign the name of the constituency for the last row to the ‘seat’ variable.’

seat = ds.Tables("mps").Rows(index).Item("Constituency")

‘If the constituency name contains an ‘apostrophe s’ it will be replaced with  a ‘double apostrophe s’. The resulting text string is then placed into the string variable ‘changedConstituency’.’

if Instr(seat, "'s") <> 0 then

changedConstituency = Replace(seat, "'s", "''s")

‘Otherwise if the constituency doesn’t contain an ‘apostrophe s’….’

else

‘Just assign the contents of the ‘seat’ variable to the string variable ‘changedConstituency’.’

changedConstituency = seat

‘Ends the ‘If then…else…end if’ block.’

end if

‘The state bag then holds the index variable ready to be used again by the other navigation buttons.’

Me.ViewState("index") = index

‘The variable filterExpression is defined as follows: it searches the field named 'constituency' in the election database for the seat held in the variable [changedConstituency].’

filterExpression = "constituency='" & changedConstituency & "'"

‘Switch over to the putDataIn function which will populate the web form with the relevant constituency’s data – see function above.’

call putDataIn()

‘Similarly switch over to the colourRecord function which will change the background colour, etc of the form depending on which party won the seat – see the function above.’

call colourRecord()

‘Assign the contents of the Session variable [subsetLabel] to the text property of the label control named ‘label3’. This Session variable is set by the calling file.’

label3.Text = Session("subsetLabel")

‘Ensure the First and Prev buttons are enabled and the Next and Last buttons are disabled.’

btnPrev.Enabled = "true"

btnFirst.Enabled = "true"

btnNext.Enabled = "false"

btnLast.Enabled = "false"

</script>

<html>

<head>

<title>Further details...</title>

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

‘The init function is run when the page loads on the client’s machine. The width and height of the window are resized depending on the user's screen resolution. The height of the window is calculated according to where the button named 'btnFirst' is on the page. Its position is established using the offsetTop property, which will return an integer in pixels specifying the element's distance from the top left hand corner of the page. An extra 70 to 100 pixels is then added to take into account any chrome that the browser may add to the window, either at the top or the bottom.

"if (self.innerHeight)" is used to distinguish between IE and non-IE browsers like Mozilla and Firefox - the latter tend to put more chrome on the window than the former.’

<script>

function init() {

if (window.screen.width < 850 ) {

var y = document.getElementById("btnFirst").offsetTop;

if (y > 550) { y = 550 }

if (self.innerHeight) {
window.resizeTo(375,y+90);
}
else {
window.resizeTo(375,y+70);
}

}

else if (window.screen.width < 1050 ) {

var y = document.getElementById("btnFirst").offsetTop;

if (y > 710) { y = 710 }

if (self.innerHeight) {
window.resizeTo(500,y+90);
}
else {
window.resizeTo(500,y+80);
}

}

else if (window.screen.width > 1250 ) {

var y = document.getElementById("btnFirst").offsetTop;

if (y > 960) { y = 960 }

if (self.innerHeight) {
window.resizeTo(610,y+100);
}
else {
window.resizeTo(610,y+90);
}

}

}

</script>

</head>

‘The first table contains the label control [label3] and a span containing ‘Close window’, which is displayed in the top right-hand side of the window to allow the user to close showMP.aspx and return to the calling file. Underneath, various textboxes, labels and other web controls make up the web form which displays the requested constituency. Below this table [table1] is the navigation panel – four buttons and a label control to hold the record number, etc..’

‘The body’s onblur event has been set to ‘self.focus()’ which means that the user must click ‘Close window’ before being able to return to the application.’

<body bgcolor="white" onload="init()" onblur="self.focus()" scroll="auto">

‘A script within the BODY element runs automatically when the page starts loading on the user's machine. It loads a different stylesheet into the 'href' attribute of the link tag shown above within the HEAD of the document.

If the user is running 800x600 then election2001800.css is loaded, if the screen width is 1280 pixels as it would be with many of the new LCD monitors, then election20011280.css is loaded, otherwise the default stylesheet - election2001.css - is used to format the web form.’

<script type="text/javascript">
<!--
if (window.screen.width > 1250) {
document.getElementsByTagName('link')[0].setAttribute('href','./otherfiles/election20011280.css');
}
else if (window.screen.width < 850) {
document.getElementsByTagName('link')[0].setAttribute('href','./otherfiles/election2001800.css');
}
//-->
</script>

<form id="Form1" method="post" runat="server">

<table width="100%"><tr>

<td><b><asp:Label runat="server" id="label3"></asp:Label>...</b></td>

<td align="right"><span style="cursor:pointer;color:blue" onClick="window.close()" id="closeShowMP">Close window</span></td></tr>

</table>

<p>

<center>

<asp:table runat="server" bgcolor=#ffffcd cellspacing=0 border=1 bordercolor=silver id="table1">

<asp:TableRow><asp:TableCell colspan="4">&nbsp;</asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="4" id="lblCountry">&nbsp;Country: <asp:textbox id="txtCountry" runat="server" ></asp:textbox>&nbsp;&nbsp;&nbsp;Region: <asp:textbox id="txtRegion" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="4" id="lblConstituency">&nbsp;Constituency: <asp:textbox id="txtConstituency" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell align="center" id="lblPlace">&nbsp;</asp:TableCell><asp:TableCell align="center" id="lblParty">Party</asp:TableCell><asp:TableCell align="center" id="lblName">Name</asp:TableCell><asp:TableCell align="center" id="lblVotes">Votes</asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell align="center" id="lblFirst"><b>1.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFirstparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFirst" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFirstvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell align="center" id="lblSecond"><b>2.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSecondparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSecond" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSecondvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell align="center" id="lblThird"><b>3.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThirdparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThird" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThirdvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row4"><asp:TableCell align="center" id="lblFourth"><b>4.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row5"><asp:TableCell align="center" id="lblFifth"><b>5.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row6"><asp:TableCell align="center" id="lblSixth"><b>6.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row7"><asp:TableCell align="center" id="lblSeventh"><b>7.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSeventhparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSeventh" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSeventhvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row8"><asp:TableCell align="center" id="lblEighth"><b>8.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEighthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEighth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEighthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row9"><asp:TableCell align="center" id="lblNinth"><b>9.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtNinthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtNinth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtNinthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row10"><asp:TableCell align="center" id="lblTenth"><b>10.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTenthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTenth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTenthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row11"><asp:TableCell align="center" id="lblEleventh"><b>11.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEleventhparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEleventh" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtEleventhvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row12"><asp:TableCell align="center" id="lblTwelfth"><b>12.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTwelfthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTwelfth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtTwelfthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row13"><asp:TableCell align="center" id="lblThirteenth"><b>13.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThirteenthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThirteenth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtThirteenthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row14"><asp:TableCell align="center" id="lblFourteenth"><b>14.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourteenthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourteenth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFourteenthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row15"><asp:TableCell align="center" id="lblFifteenth"><b>15.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifteenthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifteenth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtFifteenthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow id="row16"><asp:TableCell align="center" id="lblSixteenth"><b>16.</b></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixteenthparty" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixteenth" runat="server" ></asp:textbox></asp:TableCell><asp:TableCell align="center"><asp:textbox id="txtSixteenthvotes" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="4" align=right id="lblMajority">Majority:&nbsp;<asp:Label runat="server" id="majority" >&nbsp;</asp:Label>&nbsp;&nbsp;</asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="2" id="lblTurnout">&nbsp;Turnout: <asp:textbox id="txtTurnout" runat="server" ></asp:textbox> %</asp:TableCell><asp:TableCell colspan="2" id="lblSwing">&nbsp;Swing: <asp:textbox id="txtSwing" runat="server" ></asp:textbox> % to <asp:textbox id="txtSwingtoparty" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="4" id="lblNotes"><span id="lblNotesspan">&nbsp;Notes: </span><asp:textbox id="txtNotes" runat="server" textMode="MultiLine" wrap="True" ></asp:textbox></asp:TableCell></asp:TableRow>

<asp:TableRow><asp:TableCell colspan="4" align=center id="lblWinningparty"><br>Winning party: <asp:textbox id="txtWinningparty" runat="server" ></asp:textbox><p>Result: <asp:textbox id="txtresult" runat="server" ></asp:textbox><br><asp:textbox id="txtId" runat="server" ></asp:textbox></asp:TableCell></asp:TableRow>

</asp:table><br>

<asp:Button runat="server" id="btnFirst" onclick="LoadFirst" Text="First"></asp:Button>&nbsp;<asp:Button runat="server" id="btnPrev" onclick="LoadPrev" Text="Prev"></asp:Button>&nbsp;<asp:Label runat="server" id="Label4"></asp:Label>&nbsp;&nbsp;<asp:Button runat="server" id="btnNext" onclick="LoadNext" Text="Next"></asp:Button>&nbsp;<asp:Button runat="server" id="btnLast" onclick="LoadLast" Text="Last"></asp:Button>

</center>

</form>

</body>

</html>

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