freelanceprogrammers.org Forum Index » ASP

Post Back Wiping Out Dependent Drop Downs


View user's profile Post To page top
ltrane923 Posted: Thu Jan 13, 2005 11:51 am


Joined: 13 Jan 2005

Posts: 1
Post Back Wiping Out Dependent Drop Downs
I have 3 dependent drop down menus populated by stored procedures.
Menu 2 and 3 are based on the first selection.

If I code and stop and just using first two menus, everything is fine,
but if I tried to tack on the same logic to the third menu it
malfunctions. The third menu will not populate the first time you hit
the page, and dies if you go back to "Select a class" (index)
How can I get a third menu to work? Thanks
Here is my code:

Sub Page_Load(s As Object, e As EventArgs)
If Not Page.IsPostBack Then
Dim MyConnection As SqlConnection = new
SqlConnection(ConfigurationSettings.AppSettings("S
QLServerConnection"))



Dim MyCommand As SqlCommand = New SqlCommand()
With MyCommand
.Connection = MyConnection
.CommandText = "selClasses"
.CommandType = CommandType.StoredProcedure
End With

Dim MyDataReader As SqlDataReader

Try
MyConnection.Open()
MyDataReader = myCommand.ExecuteReader(CommandBeha
vior.CloseConnection)


ListClassN.DataSource = MyDataReader
ListClassN.DataBind()

Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())

Finally
If Not MyDataReader is Nothing Then
MyDataReader.Close()
End If

ListClassN.Items.Insert(0, "Select a class")
ListClassN.SelectedIndex = 0
End Try
End If

End Sub
//HERE IS THE SECOND MENU. THIS WORKS
Sub ClassN_change(s As Object, e As EventArgs)
If Page.IsPostBack Then
Dim MyConnection As SqlConnection = new
SqlConnection(ConfigurationSettings.AppSettings("S
QLServerConnection"))


Dim MyCommand As SqlCommand = New SqlCommand("proc_selClassDate3",
MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

Dim clnameParam As SqlParameter = MyCommand.Parameters.Add _
("@clname", SqlDbType.VarChar, 200)

clnameParam.Direction = ParameterDirection.Input
clnameParam.Value = ListClassN.SelectedItem.Text

Dim MyDataReader As SqlDataReader

Try
MyConnection.Open()
MyDataReader = myCommand.ExecuteReader(CommandBeha
vior.CloseConnection)


ClassD.DataSource = MyDataReader
ClassD.DataBind()

Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())

Finally
If Not MyDataReader is Nothing Then
MyDataReader.Close()
End If

ClassD.Items.Insert(0, "Select a date")
ClassD.SelectedIndex = 0
End Try
End If
End Sub

//OK TO HERE this is the third drop down. Everything hits the fan.

Sub location_change(s As Object, e As EventArgs)
If Page.IsPostBack Then
Dim MyConnection As SqlConnection = new
SqlConnection(ConfigurationSettings.AppSettings("S
QLServerConnection"))


Dim MyCommand As SqlCommand = New SqlCommand("Location", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

Dim clnameParam As SqlParameter = MyCommand.Parameters.Add _
("@clname", SqlDbType.VarChar, 200)

clnameParam.Direction = ParameterDirection.Input
clnameParam.Value = ListClassN.SelectedItem.Text

Dim MyDataReader As SqlDataReader

Try
MyConnection.Open()
MyDataReader = myCommand.ExecuteReader(CommandBeha
vior.CloseConnection)


ListLocation.DataSource = MyDataReader
ListLocation.DataBind()

Catch myException As Exception
Response.Write("An error has occurred: " & myException.ToString())

Finally
If Not MyDataReader is Nothing Then
MyDataReader.Close()
End If

ListLocation.Items.Insert(0, "Select a location")
ListLocation.SelectedIndex = 0
End Try
End If
End Sub


</script>
<body>
<form runat="server">

<asp:DropDownList id="ListClassN"
Datatextfield="clname"
DataValueField="classid" onSelectedIndexChanged="ClassN_change"
runat="server" AutoPostBack="True" />

<asp:DropDownList id="ClassD"
DataValueField="classid" onSelectedIndexChanged="location_change"
DataTextField="date"
runat="server" />

<asp:DropDownList id="ListLocation"
DataValueField="classid" DataTextField="location"
runat="server" />

</form>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help