Solved

DropdownList Does not remember value

Posted on 2010-09-01
2
326 Views
Last Modified: 2012-05-10
I've got a dropdownlist that is initialised like this:

 
private void getContactTypeList ()
	{
		ArrayList ContactArrayList = new ArrayList ();
		ContactArrayList.Add ("Email");
		ContactArrayList.Add ("Telephone");
		ddContact.DataSource = ContactArrayList;
		ddContact.DataBind ();
	}

Open in new window


The front end looks like this:

 
<asp:DropDownList                       
                        ID="ddContact"
                        runat="server"/>

Open in new window


When the form it is within is posted, the drop down does not remember its previous setting if it does not validate, how can I get it to remember its state?

Darren
0
Comment
Question by:darren-w-
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33574893
You should bind the dropdownlist item on page_load like this..

 

if (!IsPostBack)
{
//page loads first time
// Bind the dropdownlist here
}
else
{
// when the page loads second or more time execute code here
}
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 33575010
Thanks, that did the trick
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now