Solved

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

Posted on 2010-09-01
4
363 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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