Can't databind multiple dropdown lists to the same datareader
Posted on 2005-04-15
I am executing a datareader that then is used to populate 4 drop down lists with the results. The first drop down list gets populated with the right data but the rest only contain the "Select an Item" option that I manually insert at the top of each one. Here is the code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
Dim cmdAirportState As New SqlCommand("AirportsByState_Select", conRezSuite)
cmdAirportState.CommandType = CommandType.StoredProcedure
cmdAirportState.Parameters.Add(New SqlParameter("@AirportState", SqlDbType.Char, 2))
cmdAirportState.Parameters("@AirportState").Value = Trim(strStateCode)
Dim drAirports As SqlDataReader = cmdAirportState.ExecuteReader
ddAirFrom.DataTextField = "AirportName"
ddAirFrom.DataValueField = "AirportID"
ddAirFrom.DataSource = drAirports
ddAirFrom.Items.Insert(0, "Select an Item")
ddAirFrom.SelectedIndex = 0
ddAirTo.DataTextField = "AirportName"
ddAirTo.DataValueField = "AirportID"
ddAirTo.DataSource = drAirports
ddAirTo.Items.Insert(0, "Select an Item")
ddAirTo.SelectedIndex = 0
ddAirRetFrom.DataTextField = "AirportName"
ddAirRetFrom.DataValueField = "AirportID"
ddAirRetFrom.DataSource = drAirports
ddAirRetFrom.Items.Insert(0, "Select an Item")
ddAirRetFrom.SelectedIndex = 0
ddAirRetTo.DataTextField = "AirportName"
ddAirRetTo.DataValueField = "AirportID"
ddAirRetTo.DataSource = drAirports
ddAirRetTo.Items.Insert(0, "Select an Item")
ddAirRetTo.SelectedIndex = 0
Like I said I know the stored procedure is working as well as the datareader becasue the first dropdownlist I databind (ddAirFrom) is getting populated. Why won't the rest of them bind to the same data?