Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value in Drop-Down List control not changing 1

Status
Not open for further replies.

techsaad

Programmer
Dec 31, 2008
6
US


I have a webpage built in ASP .NET 2.0 (Visual Studio .NET 2005). My development machine has Windows .NET 2003 server.

The webform has a drop-down list. The drop-down list has AutoPostBack set to true. EnableViewState is set to true on the drop-down list control as well as on the web form.

When I select a value in the drop-down list, the page posts back and the code in the SelectedIndexChanged event handler get executed but when the webpage is reloaded - the first value in the list is selected. I cannot get the value I have selected to stay selected? How do I fix this?




Saad
 
if your code behind looks something like this
Code:
page_load(...)
{
   MyDropDownList.DataSource = GetDAta();
   MyDropDownList.DataBind();
}
then the problem is the list is rebound with every postback. you need to check for postback and then bind.

Code:
page_load(...)
{
   if (IsPostBack) return;
   MyDropDownList.DataSource = GetDAta();
   MyDropDownList.DataBind();
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top