Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Drop down list problem

Reply
Thread Tools

Drop down list problem

 
 
tom c
Guest
Posts: n/a
 
      07-10-2006
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      07-10-2006
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.

--
-Demetri


"tom c" wrote:

> 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
>
>

 
Reply With Quote
 
 
 
 
tom c
Guest
Posts: n/a
 
      07-10-2006
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


Demetri wrote:
> 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.
>
> --
> -Demetri
>
>
> "tom c" wrote:
>
> > 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
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
Multiple select drop down poplulating sub drop down scott@dettcom.com Javascript 3 11-09-2006 07:50 PM
Auto Drop down a Drop Down List xxbmichae1@supergambler.com Javascript 5 11-23-2005 01:35 AM
New to .NET, can I have one drop down box control the data of another drop down box using a database? SirPoonga ASP .Net 2 01-07-2005 10:44 PM



Advertisments