Drop down list problem

Discussion in 'ASP .Net' started by tom c, Jul 10, 2006.

  1. tom c

    tom c Guest

    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
     
    tom c, Jul 10, 2006
    #1
    1. Advertising

  2. 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
    >
    >
     
    =?Utf-8?B?RGVtZXRyaQ==?=, Jul 10, 2006
    #2
    1. Advertising

  3. tom c

    tom c Guest

    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
    > >
    > >
     
    tom c, Jul 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    799
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,047
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    514
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    295
  5. Replies:
    3
    Views:
    312
Loading...

Share This Page