Before you kill me i know theres a million different tutorials out there, but ive been stuck all day on this. (im using VB)
Basically I have a sport list and a league list.
The sports list is populated on_load from a database.
When i select an item from the sports list i want it to populate the league list with the corresponding leagues.
The solution ive attempted is to populate the leagues in the DDLSports_Selec tedIndexChanged
The items to go into the league list is also from the database and the query to select it has the currently selected value of the sports menu (i assume this is the way to do it)
However, the problem arises since obviously i have to make the sports list AutoPostBack="t rue" since there needs to be a server call to retrive the data.
When the page reloads, the form is reset and the Sports field is selecting the top item again not the new one, and hence the league list is not displaying what is needed.
I'll Stick in the VB code if that helps
Thanks Ash
Basically I have a sport list and a league list.
The sports list is populated on_load from a database.
When i select an item from the sports list i want it to populate the league list with the corresponding leagues.
The solution ive attempted is to populate the leagues in the DDLSports_Selec tedIndexChanged
The items to go into the league list is also from the database and the query to select it has the currently selected value of the sports menu (i assume this is the way to do it)
However, the problem arises since obviously i have to make the sports list AutoPostBack="t rue" since there needs to be a server call to retrive the data.
When the page reloads, the form is reset and the Sports field is selecting the top item again not the new one, and hence the league list is not displaying what is needed.
I'll Stick in the VB code if that helps
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Read Sports
Dim strSportSQL As String
strSportSQL = "SELECT sportID,sportName FROM TblSport ORDER BY sportName ASC "
Dim DataConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/Database.mdb"))
Dim SportCommand As New OleDbCommand(strSportSQL, DataConn)
DataConn.Open()
Dim SportDBReader As OleDbDataReader = SportCommand.ExecuteReader()
DDLSports.DataSource = SportDBReader
DDLSports.DataTextField = "sportName"
DDLSports.DataValueField = "sportID"
DDLSports.DataBind()
SportDBReader.Close()
DataConn.Close()
End Sub
Protected Sub DDLSports_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLSports.SelectedIndexChanged
'Read Leagues
Dim strLeagueSQL As String
strLeagueSQL = "SELECT leagueID,leagueName FROM TblLeague WHERE sportID = " & DDLSports.SelectedValue & " ORDER BY leagueName ASC"
Dim DataConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/Database.mdb"))
Dim LeagueCommand As New OleDbCommand(strLeagueSQL, DataConn)
DataConn.Open()
Dim LeagueDBReader As OleDbDataReader = LeagueCommand.ExecuteReader()
DDLLeagues.DataSource = LeagueDBReader
DDLLeagues.DataTextField = "leagueName"
DDLLeagues.DataValueField = "leagueID"
DDLLeagues.DataBind()
LeagueDBReader.Close()
End Sub
End Class
Comment