Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Drop down list is asp.net form

Drop down list is asp.net form

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasehelpquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinusk
    wrote on last edited by
    #1

    I have a drop down list in my asp.net form that I have populated from my database using datasource and databind. This bit is fine. Now I want the first option text and value to be blank. Can anyone help me??? Thanks

    T I H U 4 Replies Last reply
    0
    • V vinusk

      I have a drop down list in my asp.net form that I have populated from my database using datasource and databind. This bit is fine. Now I want the first option text and value to be blank. Can anyone help me??? Thanks

      T Offline
      T Offline
      Tuwing Sabado
      wrote on last edited by
      #2

      hi, Replace your SQL statement; Select '' As Code,'' As DescCode Union Select Code, DescCode From Table1 The idea is add one blank row to your sql statement. regards;

      1 Reply Last reply
      0
      • V vinusk

        I have a drop down list in my asp.net form that I have populated from my database using datasource and databind. This bit is fine. Now I want the first option text and value to be blank. Can anyone help me??? Thanks

        I Offline
        I Offline
        internetmouse
        wrote on last edited by
        #3

        you can do it by adding new item to dropdownlist after binding it then swap between first items and last item because when u add new item automatically add at last index or u can select items in array form database and changing what do you want to change on it then make dropdownlist data source form array . 2'nd sol. I.N.M(InterNetMouse)

        1 Reply Last reply
        0
        • V vinusk

          I have a drop down list in my asp.net form that I have populated from my database using datasource and databind. This bit is fine. Now I want the first option text and value to be blank. Can anyone help me??? Thanks

          H Offline
          H Offline
          henningbenk
          wrote on last edited by
          #4

          After DataBind() insert a new item like this: MyopDownList.Items.Insert(0,new ListItem("","")); This adds a new item at the first position.

          I 1 Reply Last reply
          0
          • H henningbenk

            After DataBind() insert a new item like this: MyopDownList.Items.Insert(0,new ListItem("","")); This adds a new item at the first position.

            I Offline
            I Offline
            internetmouse
            wrote on last edited by
            #5

            Thanks gninneh it's good :) I.N.M(InterNetMouse)

            1 Reply Last reply
            0
            • V vinusk

              I have a drop down list in my asp.net form that I have populated from my database using datasource and databind. This bit is fine. Now I want the first option text and value to be blank. Can anyone help me??? Thanks

              U Offline
              U Offline
              uadrive
              wrote on last edited by
              #6

              After you bind the data to the dropdownlist, you can add a new listitem and set the index to 0. This will store the blank row at the top of the list and even allow you to set it as selected by default. ------------------------------------- I have no prayer for that. - Stark, Farscape

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups