Making table works once not twice

S

Slim

I have page that takes some counties from a database and builds a table
adding a cell with a button to each row. I have attached a event to each
button when clicked it builds a second table that shows the states from that
country. This works fine, but in turn when you click on a stateit should
build a third table of golf courses from that state.
but when i click on a state i dont get third table, in fact i lose the
states table and end up with just the first table.

I know that all the functions work as i have tested them.

Where am I going wrong.

code below

Partial Class Enter_Default

Inherits System.Web.UI.Page

Private WithEvents btCountry As Button

Private WithEvents btState As Button

Private WithEvents btCourse As Button

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim oCountries As Countries

oCountries = New Countries

Dim i As Integer

For i = 0 To UBound(oCountries.getCountries)

Dim tr As TableRow = New TableRow

Dim td As TableCell = New TableCell

btCountry = New Button

btCountry.Attributes.Add("class", "dButtons")

btCountry.CommandArgument = oCountries.getCountries(i).id

AddHandler btCountry.Click, AddressOf CountryButtClick

btCountry.BackColor = Drawing.Color.Transparent

btCountry.BorderStyle = BorderStyle.None

btCountry.Text = oCountries.getCountries(i).Name

td.Controls.Add(btCountry)

countryTable.Rows.Add(tr)

tr.Cells.Add(td)

Next

End Sub

Sub CountryButtClick(ByVal sender As Object, ByVal e As EventArgs) Handles
btCountry.Click

Label1.Text = sender.Text & " " & sender.CommandArgument

Dim oCountry As Country

oCountry = New Country(sender.CommandArgument)

Dim i As Integer

For i = 0 To UBound(oCountry.getStates)

'On Error Resume Next

Dim tr As TableRow = New TableRow

Dim td As TableCell = New TableCell

btState = New Button

btState.Attributes.Add("class", "dButtons")

btState.CommandArgument = oCountry.getStates(i).id

AddHandler btState.Click, AddressOf StateButtClick

btState.BackColor = Drawing.Color.Transparent

btState.BorderStyle = BorderStyle.None

btState.Text = oCountry.getStates(i).Name

td.Controls.Add(btState)

stateTable.Rows.Add(tr)

tr.Cells.Add(td)

Next

End Sub

Sub StateButtClick(ByVal sender As Object, ByVal e As EventArgs) Handles
btState.Click

Label1.Text = sender.Text & " " & sender.CommandArgument

Dim oState As State

oState = New State(sender.CommandArgument)

Dim i As Integer

For i = 0 To UBound(oState.getCourses)

'On Error Resume Next

Dim tr As TableRow = New TableRow

Dim td As TableCell = New TableCell

btCourse = New Button

btCourse.Attributes.Add("class", "dButtons")

btCourse.CommandArgument = 1 'oState.getCourses(i).id

AddHandler btCourse.Click, AddressOf CourseButtClick

btCourse.BackColor = Drawing.Color.Transparent

btCourse.BorderStyle = BorderStyle.None

btCourse.Text = oState.getCourses(i).Name

td.Controls.Add(btCourse)

courseTable.Rows.Add(tr)

tr.Cells.Add(td)

Next

End Sub

Sub CourseButtClick(ByVal sender As Object, ByVal e As EventArgs) Handles
btCourse.Click

End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top