www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > .NET

    .NET Discussion and technical support for, building, using and deploying .NET sites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 07-05-2007, 03:24 PM
    Webskater Webskater is offline
    Trapped in the web
     
    Join Date: Jan 2003
    Posts: 617
    Drop down list option disappears

    If I write

    Code:
    <asp:ListItem Value="0">--Select Category --</asp:ListItem>
    It creates an <option> in a <select> drop-down list.

    To populate the drop-down list I am doing something like this to get the list items from a database:

    Code:
                    conn.Open()
                    reader = categoryComm.ExecuteReader()
                    categoryList.DataSource = reader
                    categoryList.DataValueField = "CategoryID"
                    categoryList.DataTextField = "Category"
                    categoryList.DataBind()
                    reader.Close()
    ... which works fine. But, when I populate the list from the database it deletes the <asp:ListItem> so it no longer says --Select Category-- at the top of the list. The list only contains the items from the database.

    How can I get the --Select Category-- option to stay there?

    Thanks for any help.
    Reply With Quote
      #2  
    Old 07-06-2007, 08:42 AM
    lmf232s's Avatar
    lmf232s lmf232s is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Kansas City, MO
    Posts: 1,611
    You can do this 1 of two ways. I prefer this first method
    1.
    Code:
    conn.Open()
    reader = categoryComm.ExecuteReader()
    With categoryList
    	.DataSource = reader
    	.DataValueField = "CategoryID"
    	.DataTextField = "Category"
    	.DataBind()
    	.Items.Insert(0, New ListItem("--Select Category--", ""))
    End With
    reader.Close()
    2.
    You should be able to set this property of the drop down list
    Code:
    AppendDataBoundItems="true"
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    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
    Forum Jump


    All times are GMT -5. The time now is 03:52 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.