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
Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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