asp.net dropdown selected value

Discussion in 'ASP .Net' started by =?Utf-8?B?dG1laXN0ZXI=?=, Jun 16, 2004.

  1. I must be missing something obvious. I have a drop down list in asp.net and it populates the states from a database. When I view the source of the page I get the standard option tags with the associated values. It all looks good. When I submit the form and some of the required fields aren't filled in the dropdown always reset to the first item in the list. First, how do I get it to stick. I've tried setting enableviewstate to true, but this does not seem to help. Second, and probably related, is that once the form is valid, it always passes the first item in the list regardless of which item is selected. I'm using the code below to set the value.

    cboStateProvince.SelectedValue

    And I'm populating the dropdown with the following code.

    oda.SelectCommand.CommandType = CommandType.StoredProcedure
    oda.Fill(ods)
    cboStateProvince.DataSource = ods
    cboStateProvince.DataValueField = "StateProvinceDisplayID"
    cboStateProvince.DataTextField = "StateProvinceCombined"
    cboStateProvince.DataBind()

    Any suggestions?

    Thanks,

    Todd Meister
     
    =?Utf-8?B?dG1laXN0ZXI=?=, Jun 16, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?dG1laXN0ZXI=?=

    GSK Guest

    Are you populating the dropdown on PostBack? Try putting an

    if (!Page.IsPostBack) {
    ....
    }

    around your code that initially sets the dropdown items.

    - gsk.

    "tmeister" <> wrote in message
    news:...
    > I must be missing something obvious. I have a drop down list in asp.net

    and it populates the states from a database. When I view the source of the
    page I get the standard option tags with the associated values. It all
    looks good. When I submit the form and some of the required fields aren't
    filled in the dropdown always reset to the first item in the list. First,
    how do I get it to stick. I've tried setting enableviewstate to true, but
    this does not seem to help. Second, and probably related, is that once the
    form is valid, it always passes the first item in the list regardless of
    which item is selected. I'm using the code below to set the value.
    >
    > cboStateProvince.SelectedValue
    >
    > And I'm populating the dropdown with the following code.
    >
    > oda.SelectCommand.CommandType = CommandType.StoredProcedure
    > oda.Fill(ods)
    > cboStateProvince.DataSource = ods
    > cboStateProvince.DataValueField = "StateProvinceDisplayID"
    > cboStateProvince.DataTextField = "StateProvinceCombined"
    > cboStateProvince.DataBind()
    >
    > Any suggestions?
    >
    > Thanks,
    >
    > Todd Meister
     
    GSK, Jun 16, 2004
    #2
    1. Advertising

  3. That worked. Thanks a lot.

    "GSK" wrote:

    > Are you populating the dropdown on PostBack? Try putting an
    >
    > if (!Page.IsPostBack) {
    > ....
    > }
    >
    > around your code that initially sets the dropdown items.
    >
    > - gsk.
    >
    > "tmeister" <> wrote in message
    > news:...
    > > I must be missing something obvious. I have a drop down list in asp.net

    > and it populates the states from a database. When I view the source of the
    > page I get the standard option tags with the associated values. It all
    > looks good. When I submit the form and some of the required fields aren't
    > filled in the dropdown always reset to the first item in the list. First,
    > how do I get it to stick. I've tried setting enableviewstate to true, but
    > this does not seem to help. Second, and probably related, is that once the
    > form is valid, it always passes the first item in the list regardless of
    > which item is selected. I'm using the code below to set the value.
    > >
    > > cboStateProvince.SelectedValue
    > >
    > > And I'm populating the dropdown with the following code.
    > >
    > > oda.SelectCommand.CommandType = CommandType.StoredProcedure
    > > oda.Fill(ods)
    > > cboStateProvince.DataSource = ods
    > > cboStateProvince.DataValueField = "StateProvinceDisplayID"
    > > cboStateProvince.DataTextField = "StateProvinceCombined"
    > > cboStateProvince.DataBind()
    > >
    > > Any suggestions?
    > >
    > > Thanks,
    > >
    > > Todd Meister

    >
    >
    >
     
    =?Utf-8?B?dG1laXN0ZXI=?=, Jun 17, 2004
    #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. Scott Allen
    Replies:
    1
    Views:
    865
    Scott Allen
    Aug 25, 2004
  2. Andy Sutorius

    Get selected value of dropdown from panel

    Andy Sutorius, Feb 23, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    Malik Asif Joyia
    Feb 24, 2005
  3. Andy Sutorius

    Get selected value of dropdown from panel

    Andy Sutorius, Feb 23, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    552
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Feb 24, 2005
  4. Jenna Alten
    Replies:
    6
    Views:
    13,463
    Joe Fallon
    Feb 26, 2005
  5. vishnu
    Replies:
    1
    Views:
    1,213
    Patrick.O.Ige
    Mar 25, 2006
Loading...

Share This Page