searchforanMP.aspxReturn to the Documentation page
  

functionsPage_Load
colourRecord
clearEmptyRows
clearControls
onBtnClearClicked
linkToMainMenu
putDataIn
LoadData
LoadNext
LoadPrev
LoadFirst
LoadLast

<%@ Page Language="vb" %>

‘Import the namespaces below to enable a connection to an Access 2000 database - election2001.mdb.’

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

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

<script runat="server">

‘Declare two integers and four string variables as public since they are used by several of the functions in this .aspx file. The lastrecord integer is set to the number of MPs - 659’. In addition a variable of type DataTable [dTable] is declared as Public and this is used to navigate between the records of the database - it's needed especially by the putDataIn() function, which can be seen below. Finally a variable of type DataSet [ds1] is declared to hold all the data from the election database so that it can be used by all the functions described below.

public lastrecord as integer = 659

public index as integer

public seat as string

public changedMP as string

public changedConstituency as string

public filterExpression as string

public dTable as DataTable

public ds1 as new DataSet()

‘The Page_Load function switches on the First and Last buttons and disables the Next and Prev ones.’

if txtConstituency.Text = "" then

btnNext.Enabled = "false"

btnPrev.Enabled = "false"

btnFirst.Enabled = "true"

btnLast.Enabled = "true"

end if

‘Add an onClick event to the button [btnByelection]. This button only displays on the page if there has been either a death, resignation or a void election in that constituency, any of which will naturally lead to a by-election. When the button does display the user can click it to open the showMP.aspx page to display the byelection result.’

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

‘If the page has not already been submitted to the server then....’

if not Page.IsPostback then

‘If no Session variable [fullDataSet] exists then....’

If Session("fullDataSet") Is Nothing then

‘The string variable Access2000 selects all the records from the table fullresults.’

Dim Access2000 as string = "select * from fullresults"

‘The object variable of type ODBCConnection [MyConn] takes the strConn variable as a parameter and this is fetched from the web.config file.’

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

‘The object variable of type ODBCDataAdapter [Cmd] takes the string variable Access2000 and the connection variable MyConn as parameters.’

Dim Cmd as New ODBCDataAdapter(Access2000,MyConn)

‘The Fill method of the ODBCDataAdapter puts the results of the query into the dataset named ds1 as a table named ‘mps’.’

Cmd.Fill(ds1,"mps")

‘Put the dataset into the Session variable [fullDataSet]. This will be used by other functions like LoadData, LoadNext LoadPrev, etc - see below.’

Session("fullDataSet") = ds1

‘The connection variable MyConn is now closed.’

Cmd.Dispose
MyConn.Close()

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

End if

‘Call the clearEmptyRows function - see below for more on this.’

call clearEmptyRows()

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

End if

‘The colourRecord function is called by the LoadData 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.’

In addition it will display a button on the page if there has been a byelection held in that constituency. Clicking the button will bring up the full result using showMP.aspx.

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 24 then….’

If txtResult.Text.Length > 24 then

‘Set the control’s cssClass property to 'biggerResultwidth', the value for which will be fetched from the appropriate stylesheet.’

txtResult.cssClass = "biggerResultwidth"

‘otherwise….’

Else

‘Set its cssClass property to 'smallerResultwidth'.’

txtResult.cssClass = "smallerResultwidth"

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

end if

‘If the Text property of the txtNotes web control contains either the strings 'died', 'resigned' or 'void' then....’

if Instr(txtNotes.text, "died") <> 0 or Instr(txtNotes.text, "resigned") <> 0 or Instr(txtNotes.text, "void") <> 0 then

‘Set the visible property of the button [btnByelection] to true, i.e. make it visible to the user on the page.’

btnByelection.visible = "true"

‘Define a string variable [Access2000] to hold the SELECT…FROM…WHERE… SQL statement. The statement below selects all the fields from the byelections table where the constituency is equal to the text property of the textbox [txtConstituency].’

Dim Access2000 as string = "Select * from byelections WHERE constituency='" & txtConstituency.Text & "'"

‘Declare a variable [MyConn} of type ODBCConnection which takes the strConn connection string as a parameter, the value of which is fetched from the web.config file.’

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

‘Declare a new DataSet object [ds] which will hold the data from the query above.’

Dim ds as DataSet=New DataSet()

‘Declare a new ODBCDataAdapter object [Cmd] with the parameters Access2000 and MyConn. This will pull the data from the Access2000 database [election2001.mdb] and put it into the dataset [ds].’

Dim Cmd as New ODBCDataAdapter(Access2000,MyConn)

‘Fill the dataset and call the table created ‘mps’.’

Cmd.Fill(ds,"mps")

‘Create session variables to hold the selected constituency [txtConstituency.Text], the string 'Result of the By-election' and the dataset itself [ds], which will be used by showMP.aspx when it opens.’

Session("subsetDataSet") = ds

Session("subsetLabel") = "Result of the By-election"

Session("picked") = txtConstituency.Text

‘Tidy up and close the connection object.’

MyConn.Close

‘Otherwise....’

else

‘Set the visible property of the button [btnByelection] to false, i.e. make it invisible to the user on the page.’

btnByelection.visible = "false"

end if

‘Return to the function that originally called the colourRecord() function.’

return

‘The clearEmptyRows() function is called when the searchforanMP page is first loaded onto the user's machine - see the Page_Load() function above. It merely displays the first few rows of the form and, in particular, rows 4 - 16 will be hidden using this function. It just makes it a little easier to digest visually.’

‘Declare two variables r as a TableRow which will represent each row of the ASP table web control [table1] and i as an integer which is used in the FOR EACH loops below.’

dim r as TableRow

dim i as integer

‘Start a FOR EACH loop using each row in the ASP table web control [table1].’

for each r in Table1.Rows

‘Set i initially to 4 and its upper limit to 16. We want to show just the first few rows of the ASP table [table1].’

for i = 4 to 16

‘If the id of the row is row4, for example, then set the visibility of the row to 'false' so that it is NOT displayed on the screen. Note only those rows on the web form which might need to be hidden are given ids from row4 to row16.’

if r.ID = "row" & i.ToString() then r.visible = "false"

‘Proceed to the next row and set the visibility to 'false' also - all the remaining rows down to row 16 will be hidden as well.’

next

next

‘Return to the function that originally called clearEmptyRows() - the Page_Load function above.’

return

‘The clearControls function runs when the user clicks the ‘Clear’ button on the web page. It is called from the OnBtnClearClicked() function which is documented below. It clears all the data from the textboxes and labels on the form.’

‘Starts a FOR EACH...NEXT loop that looks at the type of web server control on the web form.’

for each ctrl As Control in Controls

‘If the control is a textbox then set its text property to "". Note the control has to be first cast as a textbox using the CType function before its text property can be set.’

If TypeOf ctrl Is TextBox then CType(ctrl,TextBox).Text = ""

‘If the control is a label AND its ID is either label3, majority or label4 then set its text property to "". As before, the control has to be first cast as a label using the CType function before its text property can be set to "".’

if TypeOf ctrl Is Label AND ((ctrl.ID = "Label3") or (ctrl.ID = "majority") or (ctrl.ID ="Label4")) then CType(ctrl, Label).Text = ""

‘Check to see if the control has any child controls within it using the HasControls method. If it has run the clearControls function over them as well and clear the textboxes and labels of any text.’

if ctrl.HasControls then clearControls(ctrl.Controls)

next

‘Return to the calling function which is the OnBtnClearClicked() subroutine below.’

return

‘This function resets all the text boxes and labels on the form when the ‘Clear’ button is clicked.’

‘Calls the clearControls function with all the controls on the page as a parameter. This function is described above.’

clearControls(Page.Controls)

‘Sets visible property of the button [btnByelection] to false so that it doesn't display on the page.’

btnByelection.Visible = "false"

‘Sets the cssClass of the ASP table [table1] to the normal style.’

table1.cssClass = "normal"

‘Returns the navigation buttons at the bottom of the form to their default state - Next and Previous are disabled and First and Last are enabled.’

btnNext.Enabled = "false"

btnPrev.Enabled = "false"

btnFirst.Enabled = "true"

btnLast.Enabled = "true"

‘Calls the clearEmptyRows() function, already described above, to just show the first few rows of the form on the screen.’

call clearEmptyRows()

‘Redirects the user to the mainmenu.aspx page when the LinkButton control is clicked – Return to the Main menu.’

Response.Redirect("mainmenu.aspx")

‘The putDataIn() function is called by the LoadData, 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’.’

‘Starts a TRY...CATCH...END TRY block.’

try

‘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 )

‘Both the Label3 and txtMP textboxes have their text properties set to "".’

Label3.Text = ""

txtMP.Text = ""

‘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'.’

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 = txtId.Text & " of " & lastrecord

‘If there is an error of some sort use 'Catch' to show a message.’

catch

‘Set the text property of the label control [Label3] to an appropriate message.’

Label3.Text = "Sorry, there is no data for that MP."

‘Ends the TRY...CATCH...END TRY block.’

end try

‘Assigns the name of the constituency to the Session variable 'constituency'. This will be used in an error message within the errorByelections file - see errorByelections.aspx.’

Session("constituency") = txtConstituency.Text

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

return

‘The LoadData function runs when the user clicks the ‘Load MP’s Details’ button on the web page.’

‘Check that an MP’s name has been entered into the textbox [txtMP.Text].’

If txtMP.Text <> "" THEN

‘The Instr function checks to see whether the MP’s name contains an apostrophe. If there is an apostrophe in the MP's name, e.g. Mike O'Brien, it is replaced with ‘two apostrophes’ i.e. “Mike O''Brien”. The resulting text string is placed into the variable changedMP - this is then used by the string variable [filterExpression] below.’

if Instr(txtMP.Text, "'") <> 0 then

changedMP = Replace(txtMP.Text, "'", "''")

else

changedMP = txtMP.Text

end if

‘The dataset [ds1] is retrieved from the Session variable [fullDataSet] which was created within the Page_Load function - see above.’

ds1 = Session("fullDataSet")

‘The variable dTable is set to the table mps which is in the dataset [ds1].’

dTable = ds1.Tables("mps")

‘The variable filterExpression is defined as follows: it searches the field named 'first' in the election database for the MP entered into the textbox [txtMP].’

filterExpression = "first='" & changedMP & "'"

‘The putDataIn() function is called to populate the web form with the data for the requested MP - see that function above.’

call putDataIn()

‘The colourRecord function is called to colour the background of the form with the winning party’s colour.’

call colourRecord()

‘Set the text property of the textbox [txtMP] to the contents of the variable [changedMP]. Note if the variable contains two apostrophes use the Replace method to change it back to just the one. This avoids the textbox [txtMP] displaying an MP's name wrongly e.g. Eddie O''Hara.’

txtMP.Text = changedMP.Replace("''", "'")

‘If the text property of the textbox [txtId] isn't blank i.e. it contains a record number, then set the state bag variable [index] to the record number minus 1.’

if txtId.Text <> "" then Me.ViewState("index") = txtId.Text - 1

‘If the label control [Label3] isn't blank i.e. it contains an error message, then set the visible property of the button [btnByelection] to false.’

if Label3.Text <> "" then btnByelection.Visible = "false"

‘If the textbox control [txtFirst] is blank then set the cssClass property of the ASP table control [table1] to normal and 'switch off' the btnNext and btnPrev navigation buttons.’

If txtFirst.Text = "" then

table1.cssClass = "normal"

btnNext.Enabled = "false"

btnPrev.Enabled = "false"

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

end if

‘If the text property of the textbox control [txtId] isn't equal to 1 and the textbox [txtConstituency] isn't blank then enable the navigation buttons btnPrev and btnFirst.’

If txtID.Text <> "1" and txtConstituency.Text <> "" then

btnPrev.Enabled = "true"

btnFirst.Enabled = "true"

‘If the text property of the textbox control [txtId] isn't equal to the contents of the variable [lastrecord] i.e. 659 and the textbox [txtConstituency] isn't blank then enable the navigation buttons btnNext and btnLast. Note: the ToString method is used to convert an integer to a string to avoid an error in the comparison with the Text property of the web control named 'txtID'.’

If txtID.Text <> lastrecord.ToString and txtConstituency.Text <> "" then

btnNext.Enabled = "true"

btnLast.Enabled = "true"

‘If the text property of the textbox control [txtId] is equal to 1 then enable and disable the following navigation buttons.’

If txtID.Text = "1" then

btnFirst.Enabled = "false"

btnPrev.Enabled = "false"

btnLast.Enabled = "true"

btnNext.Enabled = "true"

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

end if

‘If the text property of the textbox control [txtId] is equal to lastrecord.ToString i.e. 659, then enable and disable the following navigation buttons.’

If txtID.Text = lastrecord.ToString then

btnLast.Enabled = "false"

btnNext.Enabled = "false"

btnFirst.Enabled = "true"

btnPrev.Enabled = "true"

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

end if

else

‘Error message to display if the user doesn't enter any text into the textbox [txtMP].’

Label3.Text = "Please enter the name of an MP."

‘Set the visible property of the button [btnByelection] to false.’

btnByelection.Visible = "false"

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

end if

‘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 election database, which is sorted alphabetically on the constituency field.’

‘Retrieve the dataset [ds1] from the Session variable [fullDataSet].’

ds1 = Session("fullDataSet")

‘The variable dTable is set to the table mps which is in the dataset [ds1].’

dTable = ds1.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

‘Check to see if the record displayed is the last record - the user shouldn't be able to click the Next button if the last constituency [Yorkshire East] is displayed on the screen.’

If index <= ds.Tables("mps").Rows.Count - 1 then

‘The state bag then holds the newly incremented index variable. The string variable seat is set to the constituency of the row which has the same number as the index variable.’

Me.ViewState("index") = index

seat = ds1.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")

else

changedConstituency = seat

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

end if

‘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 & "'"

‘The putDataIn() function is called to populate the web form with the data for the requested constituency - see that function above.’

call putDataIn()

‘The colourRecord function is called to colour the background of the form with the winning party’s colour.’

call colourRecord()

Else

‘If the user has reached the last record in the database then display an appropriate message using the ASP label control [Label3] and 'switch off' the navigation button [btnNext].’

Label3.Text = "Sorry, you have reached the end of the database."

btnNext.Enabled = "false"

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

End if

‘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"

end if

‘Ensure the First and Prev navigation buttons are enabled.’

btnFirst.Enabled = "true"

btnPrev.Enabled = "true"

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

If txtId.Text - 1 <> "0" THEN

ds1 = Session("fullDataSet")

dTable = ds1.Tables("mps")

index = Me.ViewState("index")

index -= 1

Me.ViewState("index") = index

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

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

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

else

changedConstituency = seat

end if

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

call putDataIn()

call colourRecord()

Else

Label3.Text = "Sorry, you have reached the beginning of the database."

btnPrev.Enabled = "false"

End if

if index = 0 then

btnPrev.Enabled = "false"

btnFirst.Enabled = "false"

end if

btnLast.Enabled = "true"

btnNext.Enabled = "true"

‘Similar to the LoadNext function but moves the user to the first record in the database - Aberavon.’

dim index as integer = 0

Me.ViewState("index") = index

ds1 = Session("fullDataSet")

dTable = ds1.Tables("mps")

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

filterExpression = "constituency='" & seat & "'"

call putDataIn()

call colourRecord()

btnNext.Enabled = "true"

btnPrev.Enabled = "false"

btnLast.Enabled = "true"

btnFirst.Enabled = "false"

‘Similar to the LoadNext function but moves the user to the last record in the database – Yorkshire East.’

ds1 = Session("fullDataSet")

dTable = ds1.Tables("mps")

index = ds1.Tables("mps").Rows.Count - 1

Me.ViewState("index") = index

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

filterExpression = "constituency='" & seat & "'"

call putDataIn()

call colourRecord()

btnNext.Enabled = "false"

btnPrev.Enabled = "true"

btnLast.Enabled = "false"

btnFirst.Enabled = "true"

</script>

<html>

<head>

<title>Search for an MP...</title>

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

</head>

‘Various textboxes and labels make up the web form below which are mostly contained within one ASP table. Underneath the table [table1] is the navigation panel – four buttons and a label control to hold the record number, etc.’

<body bgcolor="white">

‘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 rowspan="2" width="85px"><img src="./images/ballotbox.jpg" title="Cast your vote wisely!"></td><td><asp:Label id="Label1" runat="server" ><u>Search for an MP</u></asp:Label></td>

<td align="right"><asp:LinkButton id="LinkToEdit" onclick="linkToMainMenu" runat="server" Text="Return to the Main menu"></asp:LinkButton></td></tr>

<tr><td colspan="2">&nbsp;</td></tr>

</table>

<p>

<asp:Label id="Label2" runat="server" >Enter MP's name:</asp:Label> <asp:textbox id="txtMP" runat="server" ></asp:textbox> <asp:button id="btnLoad" onclick="LoadData" runat="server" forecolor="White" backcolor="Navy" text="Load MP's details"></asp:button> <asp:button id="btnClear" onclick="OnBtnClearClicked" runat="server" forecolor="White" backcolor="Navy" text="Clear"></asp:button><br>

<p>

<asp:Label id="Label3" runat="server" foreColor="red" ><b></b></asp:Label><p>
<asp:Button id="btnByelection" runat="server" forecolor="White" backcolor="Navy" text="By-election result" Visible="False"></asp:Button>

<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"><i>Majority</i>:&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><p></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>

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