Solved

.NET ASP C# how do you set dropdown default in pageload?

Posted on 2010-09-01
4
362 Views
Last Modified: 2013-11-08
Expert:
I have a 3.5 dot net C# web application with a drop down that is currently loaded from the database. However now I need to set the dropdown default to --- when the web page first appears. Can some one show me the code how this can be done in the page load function such that "--- " appears in the dropdown list when the first time page appears!
0
Comment
Question by:tcmmaxt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Assisted Solution

by:asutorius
asutorius earned 125 total points
ID: 33576156
Dropdownlist1.Items.Add("0",new ListItem(0,"---"));
0
 
LVL 9

Assisted Solution

by:richard_hughes
richard_hughes earned 125 total points
ID: 33576209
Hello tcmmaxt

After the dropdown has been populated, try this:

Thanks,

Richard Hughes
myDropDown.Items.Insert(0, new ListItem("---", "0"));

Open in new window

0
 
LVL 3

Accepted Solution

by:
vijayanandgawle earned 150 total points
ID: 33576323
ddlRouteGroup.Items.Add(new ListItem("No Route Groups", ""));

 ddlFamily.Items.Insert(0, new ListItem("No Addresses Found", "-1"));

while in inser we can give postion to insert that value.

All other cases covered in below links
Ref:http://peterkellner.net/2007/10/17/dropdownlistdefaultsetting/
http://forums.asp.net/p/1122833/1758287.aspx

0
 
LVL 11

Assisted Solution

by:princeatapi
princeatapi earned 100 total points
ID: 33576482
very important thing is you must add the code inside the

 if (!Page.IsPostBack)
 {
      // After binding your ddlist  from db
     // Code to insert your default list item at 0th position
}
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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