DropDown List

M

Manoj Paramu Das

DropDwonList.SelectedItem.Value returns only the first record value, no
matter when you select. any help would be appreciated.

Thnaks Manoj
 
S

Sean McKaharay

Read this excerpt:


Adding Controls at the Right Time
We already know that when adding controls dynamically through the page's
code portion the controls must be added on every postback. But when in the
page lifecycle should the controls be added? At first guess, we might decide
to put such code in the Page_Load event handler, causing the controls to be
added during the Load stage of the page's lifecycle. This would work fine if
we don't need to worry about saving the controls' view state across
postbacks, but if we do need to persist the view state of the dynamically
added controls the Load stage is not where we should be adding these
controls.

If we need our dynamically added controls to maintain their view state it is
paramount that these controls be added before the Load View State stage.
That is, these controls must exist within the page's control hierarchy
before the view state is loaded. There's only one stage before Load View
State - Initialization. That means, if we want our dynamic controls to
persist view state we must add them to the control hierarchy in the page's
Init event.

If you are using Visual Studio .NET, the code-behind class already contains
an event handler for the page's Init event. This event handler (named
Page_Init in VB.NET code-behind classes and OnInit in C# code-behind
classes) is tucked away in the hidden "Web Form Designer Generated Code"
region. What I typically do is create a separate method in the code-behind
class and simply call this method from the Init event handler. Once you have
configured everything so that the dynamic controls are added during the
Initialization stage, you can then read/write the controls' properties in
the Load stage. You'll find that the users' interactions with the dynamic
controls remains "remembered" across postbacks if you follow this pattern.



That should help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top