Drop down list problem

T

tom c

I have a dropdown list box on an ASP.Net 1.1 webform. I populate it
from a dataset in code. Everything looks fine and I can see all the
values in the dropdownlist. I can select a value and I see that new
selected value in the list box. However, when I look for the values in
code, I see the original value from the list box. The one that was
loaded first and showed up before I selected a new one.

This is the code I use to look at the value:

c = Me.DropDownListHotels.SelectedValue.ToString
d = Me.DropDownListHotels.SelectedItem.ToString
k = Me.DropDownListHotels.SelectedItem.Text

This is the code I use to load the list box:

Sub LoadHotels()
Dim password, firstname, userid, loginid, sql As String
Dim cn As New
OleDb.OleDbConnection(Mod1.buildConnectionString("CIADSTATViewer.mdb"))
sql = "SELECT name, propertycode FROM hotels)"
Dim da As New OleDb.OleDbDataAdapter(sql, cn)
Dim ds As DataSet = New DataSet("Users")
da.Fill(ds)
cn.Close()
' Populate drop down list
Me.DropDownListHotels.DataSource = ds.Tables(0)
Me.DropDownListHotels.DataTextField = "name"
Me.DropDownListHotels.DataValueField = "propertycode"
Me.DropDownListHotels.DataBind()
Catch ex As Exception
Mod1.ErrorMessage(ex, "LoadHotels")
End Try
End Sub
 
G

Guest

Is your LoadHotels method being called BEFORE you check the values?

By the way, a DataSet is WAY WAY too much overhead just to fill a drop down
list. Consider using the DataReader or better yet one of the NameValue pair
collection classes such as Dictionary or the NameValuePair collection itself
from a Business tier.

Anyway, hope that helps.
 
T

tom c

Thanks Demetri, I was calling LoadHotels from Page_Load and it got
reloaded after I set it. I appreciate your help. I get so fascinated
by new technology that I don't look for simple solutions.

Tom
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top