Solved

DropdownList Does not remember value

Posted on 2010-09-01
2
328 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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