Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 5th, 2004, 04:04 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dorothee
Default DropDownList Selected Index = -1??

Hello,

I am a newbie and I am trying to get the dropdownlists on my page to default to 'Choose' or 'Select' by default. However the dropdownlists are binding to a database and those aren't values in it. Please help.

Thanks

  #2 (permalink)  
Old June 5th, 2004, 04:10 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Usually you do this by first binfing the DDL to the dataset, then you manually add a "Choose" item at the beginning:

ddl.Items.Insert(0, New ListItem(...))

This will add the new ListItem at the beginning of the list.

Peter
-------------------------
Work smarter, not harder
  #3 (permalink)  
Old June 5th, 2004, 04:18 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dorothee
Default

I am sure it is simple but I am a bit thick.
here is my dropdownlist
<asp:DropDownList ID="DropDownList1" DataSource="<%# DataSet1.DefaultView %>" DataTextField="Bldg_Code" DataValueField="Bldg_Code" runat="server"></asp:DropDownList>

is the line you wrote to be added to this tag or does it have to go back in the head?

sorry and confused.


  #4 (permalink)  
Old June 5th, 2004, 04:31 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

That line needs to be in the code-behind of the control. I was making the poor assumption that you were binding the control in code-behind/inline code and not directly within the markup.

An alternative is to build the first item into your query. In MSSQL you could union two queries to get the first item and then the rest:

SELECT 'Choose...', -1 AS <value field>
UNION
SELECT <text field>, <value field> FROM <table>...
ORDER BY <value field>
  #5 (permalink)  
Old June 11th, 2004, 03:08 AM
Authorized User
 
Join Date: Jun 2004
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to dorothee
Default

Thanks Peter. I don't know much about code-behind yet. so I'll leave that one for now.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
find the selected index of the dropdownlist suneet.pant ASP.NET 2.0 Basics 0 May 22nd, 2008 03:45 AM
DropDownList, DataSource and Selected Items kingroon ASP.NET 2.0 Basics 2 February 25th, 2008 10:41 AM
How to get datagrid selected index pl help me msrnivas General .NET 1 July 1st, 2005 08:03 AM
selected value from dropdownlist control netwizard_01 ASP.NET 1.0 and 1.1 Basics 3 January 20th, 2004 09:29 AM



All times are GMT -4. The time now is 09:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.