By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,534 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,534 IT Pros & Developers. It's quick & easy.

asp.net dropdown selected value

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
GSK
Are you populating the dropdown on PostBack? Try putting an

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

around your code that initially sets the dropdown items.

- gsk.

"tmeister" <tm******@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
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

Nov 18 '05 #2

P: n/a
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" <tm******@discussions.microsoft.com> wrote in message
news:A7**********************************@microsof t.com...
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


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.