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. Help with Drop Down Lists

Help with Drop Down Lists

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestion
5 Posts 2 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.
  • H Offline
    H Offline
    HarryBo
    wrote on last edited by
    #1

    Hi, I am a junior developer, developing a simple web-application. As i am new to ASP.NET i don't know how i go about taking the text in a drop down list then enter it into a table using its ID from the same table. To be more clear I have a users form with only one ddlist stating the access levels of admin, dev, and user, taken from an accesslevels table which holds those three descriptions and their ids (1,2,3). I need to be able to select the description from the ddlist and when submit is pressed the id of the accesslevel needs to be stored in the user table. Does that make sense? Many Thanks Harry "Not everything that can be counted counts, and not everything that counts can be counted" Albert Einstein.

    H 1 Reply Last reply
    0
    • H HarryBo

      Hi, I am a junior developer, developing a simple web-application. As i am new to ASP.NET i don't know how i go about taking the text in a drop down list then enter it into a table using its ID from the same table. To be more clear I have a users form with only one ddlist stating the access levels of admin, dev, and user, taken from an accesslevels table which holds those three descriptions and their ids (1,2,3). I need to be able to select the description from the ddlist and when submit is pressed the id of the accesslevel needs to be stored in the user table. Does that make sense? Many Thanks Harry "Not everything that can be counted counts, and not everything that counts can be counted" Albert Einstein.

      H Offline
      H Offline
      Harry Kris
      wrote on last edited by
      #2

      I am not sure if you need help with saving data back in to the database OR finding the ID corresponding to access level selected by the user. If its the ID, Each item in the DropDownList has Text and Value. Text is the description that you see in the GUI and Value is something you associate with each description. In your case, 'Admin' is the text and '1' is the value. If myddl is the DropDownList, then myddl.Items.Add(new ListItem('Admin','1')); will add 'Admin' to the dropdownlist. Does that answer your question ? HTH Harry :-)

      H 1 Reply Last reply
      0
      • H Harry Kris

        I am not sure if you need help with saving data back in to the database OR finding the ID corresponding to access level selected by the user. If its the ID, Each item in the DropDownList has Text and Value. Text is the description that you see in the GUI and Value is something you associate with each description. In your case, 'Admin' is the text and '1' is the value. If myddl is the DropDownList, then myddl.Items.Add(new ListItem('Admin','1')); will add 'Admin' to the dropdownlist. Does that answer your question ? HTH Harry :-)

        H Offline
        H Offline
        HarryBo
        wrote on last edited by
        #3

        Thank you that is a sort of help. But, I have added the values from the access levels table through this method: i formed a sql string using a stored procedure to pull the accesslevels from the table, then formed the dataadapter and then filled a dataset. This is then used to fill the ddl. What i need help to do is taking the selected item in the combo, find the corresponding id in the accesslevels table and store that id in the users table in the database. How? as i am lost, is it possible to do it this way or can you suggest any other ideas..... Many Thanks again, Harry

        H 1 Reply Last reply
        0
        • H HarryBo

          Thank you that is a sort of help. But, I have added the values from the access levels table through this method: i formed a sql string using a stored procedure to pull the accesslevels from the table, then formed the dataadapter and then filled a dataset. This is then used to fill the ddl. What i need help to do is taking the selected item in the combo, find the corresponding id in the accesslevels table and store that id in the users table in the database. How? as i am lost, is it possible to do it this way or can you suggest any other ideas..... Many Thanks again, Harry

          H Offline
          H Offline
          Harry Kris
          wrote on last edited by
          #4

          Hi, Instead of using the dataset to fill the ddl, can you loop through each of the rows in datatable and add items to ddl with proper TEXT and VALUE. This way you would have the access ID as soon as the user selects any access level. To answer the second part of storing the id in the database, Can you write another stored procedure with IN parameters to do the update/insert into the database ? If yes, you can invoke this stored procedure to store the id. makes sense ? HTH Harry :-)

          H 1 Reply Last reply
          0
          • H Harry Kris

            Hi, Instead of using the dataset to fill the ddl, can you loop through each of the rows in datatable and add items to ddl with proper TEXT and VALUE. This way you would have the access ID as soon as the user selects any access level. To answer the second part of storing the id in the database, Can you write another stored procedure with IN parameters to do the update/insert into the database ? If yes, you can invoke this stored procedure to store the id. makes sense ? HTH Harry :-)

            H Offline
            H Offline
            HarryBo
            wrote on last edited by
            #5

            Thanks, do you know how to do it with the selected index property instead? Sorry to be a pain. Someone also mentioned reverse lookups are they possible? Many Thanks Harry

            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