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. DataBound DropDownList Questions (2)

DataBound DropDownList Questions (2)

Scheduled Pinned Locked Moved ASP.NET
databasehelp
6 Posts 3 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.
  • F Offline
    F Offline
    ffowler
    wrote on last edited by
    #1

    Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.

    B B 2 Replies Last reply
    0
    • F ffowler

      Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.

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

      You can do one thing when you want ot add user at that time don't bind it from datasource just add user using .ADD else bind it to datasource. if you want ot make it more custom read each item from database one by one and add it.

      Cheers!! Brij

      F 1 Reply Last reply
      0
      • B Brij

        You can do one thing when you want ot add user at that time don't bind it from datasource just add user using .ADD else bind it to datasource. if you want ot make it more custom read each item from database one by one and add it.

        Cheers!! Brij

        F Offline
        F Offline
        ffowler
        wrote on last edited by
        #3

        I thought I would have to code it but I wasn't sure if it could be done without the coding. So that answers that, but how do I make a specific one selected?

        B 1 Reply Last reply
        0
        • F ffowler

          I thought I would have to code it but I wasn't sure if it could be done without the coding. So that answers that, but how do I make a specific one selected?

          B Offline
          B Offline
          Brij
          wrote on last edited by
          #4

          There are two prperties of dropdownlist SelectedIndex and SelectedValue.If you know which item/index you need to show as selected then you can set it by above properties.

          Cheers!! Brij

          F 1 Reply Last reply
          0
          • B Brij

            There are two prperties of dropdownlist SelectedIndex and SelectedValue.If you know which item/index you need to show as selected then you can set it by above properties.

            Cheers!! Brij

            F Offline
            F Offline
            ffowler
            wrote on last edited by
            #5

            That's the ticket. Thanks guys!

            1 Reply Last reply
            0
            • F ffowler

              Hello All, This may be a simple enough questions but I cannot seem to make them work for me, therefore I am looking for any breadcrumbs that you guys can offer. I have a simple DropDownList that is bound to an SQL DataSource that just pulls users names from a table. No problem there. What I need to do in certain situations are the following: A - Add a new item to the list (No User) B - Have that new item first in the list as being selected. I have tried adding the .ADD method to the DataBound event, and it appears to be run but that value is not in the list after the page loads. Additionally I cannot make any other items in the list selected (instead of USERA being displayed I would like USERC displayed upon load). Any assistance will be appreciated.

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6

              After you pull data in DropDownList1 from tabel then add new item by code: DropDownList1.Items.Add(new ListItem("Please select one user","")); DropDownList1.SelectedValue = "";


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

              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