Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DropDownList initialization question
Message
General information
Forum:
ASP.NET
Category:
Web forms
Miscellaneous
Thread ID:
00900902
Message ID:
00901149
Views:
18
>>My form has several DropDownLists on it. I want to populate them from tables, as I think I mentioned...
>
>Richard, make sure you only do the below code when the form is first loaded, and not on a post back. If you do it on a postback it looses the currently selected setting. Wrap your populate code with:
>
>if (! IsPostBack)
>{
> // This code only runs the FIRST time your page loads
>
> ...Code to get your data and bind to the combos...
>}
>
>BOb
----------------------
Bob,
I've tried loading my lookups 3 different ways
1st way was to create the lookups in the form load. That had the problem you mention about loosing the currently selected setting

2nd way was to create the lookups in the form load, but wrap them in code that used a session variable to indicate if this is not the first time the form load has run (aka - we're in a postback). This had the problem that the DropDownLists would loose their contents... they'd become empty.

3rd way was to create the lookups in the click event that would take the user to the panel the DropDownLists are on. On that panel is a button to display (in a textbox) the proposed changes (I'm building a WHERE clause for my SELECT command). The button triggers a postback and sets txtProposed.Text to the new WHERE clause, built from the DropDownList selections. This had the problem that (even before the new WHERE clause could be built) the DropDownLists would loose their contents... they'd become empty and the txtProposed.Text would remain empty.

How do I get the lookups, the contents of the DropDownLists, and their selections, to persist between postbacks?
(btw - the DropDownLists EnableViewState is set to True... I thought that was supposed to make the data persist... but it doesn't...is that because it's coming from tables? If so, how do I get the tables to persist? OR how do I fake it out and make it work?)

Rick
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform