Strange dropdown behavior

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi all:

I have a web form with a drop-down listbox on it. If I populate the
drop-down using the forms designer, all is well. However, if I write code to
populate the drop-down in the "page load" method, if I then put code in the
command button
"Click" method, I do not get the right value out of the box using

drpSubject.SelectedItem.Value.ToString()
for some reason, it just selects the first item in the drop down.

Anyone know what is going on here? It almost seems like the page reloads
before the value is pulled from the drop-down, so on reload the drop-down
repopulates, and the selected item is the first one...

TIA for any and all help.

John.
 
-----Original Message-----
Hi all:

I have a web form with a drop-down listbox on it. If I populate the
drop-down using the forms designer, all is well. However, if I write code to
populate the drop-down in the "page load" method, if I then put code in the
command button
"Click" method, I do not get the right value out of the box using

drpSubject.SelectedItem.Value.ToString()
for some reason, it just selects the first item in the drop down.

Anyone know what is going on here? It almost seems like the page reloads
before the value is pulled from the drop-down, so on reload the drop-down
repopulates, and the selected item is the first one...

TIA for any and all help.

John.




.
You need to use the if(!IsPostBack) command this will
make the drop down list only load its info the first time
the page is loaded. Here is an example of what to put in
the Page_Load method.

if(!IsPostBack)
{
Fill In Drop-Down
}

Good Luck,
Adam
 
Hi Adam:

Thanks for the reply, but no joy. That code crashes the page...I don't
understand why clicking the Submit button reloads the page...

John.
 
Back
Top