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