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. set dropdownlist default value

set dropdownlist default value

Scheduled Pinned Locked Moved ASP.NET
databasequestion
10 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.
  • E Offline
    E Offline
    eyeseetee
    wrote on last edited by
    #1

    Hi I ave a dropdownlist which is populated from a database However how do i set the default value of the dd as Select thanks in advance cheers

    B V 2 Replies Last reply
    0
    • E eyeseetee

      Hi I ave a dropdownlist which is populated from a database However how do i set the default value of the dd as Select thanks in advance cheers

      B Offline
      B Offline
      bhanu12345
      wrote on last edited by
      #2

      use the below code dd.Items.Insert(0, "Select"); Bhanu

      E 1 Reply Last reply
      0
      • B bhanu12345

        use the below code dd.Items.Insert(0, "Select"); Bhanu

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #3

        Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)

        S B B 3 Replies Last reply
        0
        • E eyeseetee

          Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          Totaly depends where are you writing the suggested lines Could you provide the code after binding the datasource just insert select string at 0 index it's simple

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          1 Reply Last reply
          0
          • E eyeseetee

            Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)

            B Offline
            B Offline
            bhanu12345
            wrote on last edited by
            #5

            Write that line of code after binding the data to dropdownlist Bhanu

            1 Reply Last reply
            0
            • E eyeseetee

              Hi I ave a dropdownlist which is populated from a database However how do i set the default value of the dd as Select thanks in advance cheers

              V Offline
              V Offline
              Vinay Dornala
              wrote on last edited by
              #6

              If DataSet.Tables.Count > 0 Then dtTable = DataSet.Tables(0) objList = CType(drpDropDown, System.Web.UI.WebControls.DropDownList) With objList .Items.Clear() .DataValueField = "value" .DataTextField = "text" dtRow = dtTable.NewRow() dtRow(0) = -1 dtRow(1) = "--Select--" dtTable.Rows.InsertAt(dtRow, 0) .DataSource = DataSet .DataBind() End With

              E 1 Reply Last reply
              0
              • E eyeseetee

                Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)

                B Offline
                B Offline
                Bassam Saoud
                wrote on last edited by
                #7

                If you are using SQLDataSource, I think you'll need to add the code provided in the Databound event of the dropdownlist

                S 1 Reply Last reply
                0
                • B Bassam Saoud

                  If you are using SQLDataSource, I think you'll need to add the code provided in the Databound event of the dropdownlist

                  S Offline
                  S Offline
                  Sandeep Akhare
                  wrote on last edited by
                  #8

                  i think no need to to have databound event just need to insert the string at perticular index

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                  B 1 Reply Last reply
                  0
                  • S Sandeep Akhare

                    i think no need to to have databound event just need to insert the string at perticular index

                    Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                    B Offline
                    B Offline
                    Bassam Saoud
                    wrote on last edited by
                    #9

                    sure, all you need is to insert the string at the particular index after the data binding have occured.With the databound event you can trap the binding process.

                    1 Reply Last reply
                    0
                    • V Vinay Dornala

                      If DataSet.Tables.Count > 0 Then dtTable = DataSet.Tables(0) objList = CType(drpDropDown, System.Web.UI.WebControls.DropDownList) With objList .Items.Clear() .DataValueField = "value" .DataTextField = "text" dtRow = dtTable.NewRow() dtRow(0) = -1 dtRow(1) = "--Select--" dtTable.Rows.InsertAt(dtRow, 0) .DataSource = DataSet .DataBind() End With

                      E Offline
                      E Offline
                      eyeseetee
                      wrote on last edited by
                      #10

                      Hi all thanks for the replies, wish my other posts got this many repliers!! I had to add in 'select' into my select statement so it set the value as select cheers thanks

                      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