Saving DropDown List Selected Values to database?

Hello everyone.  

I'm quite new to ASP, Visual Web Developer, and C#. I've been going over the tutorials trying to absorb everthing I can and I've also been reading up on SQL. Anyways, Im trying to make a web application that I can use to update my database. I've been over the tutorials that demonstrate how to use GridView and Details View to display, update and insert data but I don't think these will work for me as the data I need to update is all based upon a variety of different queries which calculate certain values. Sometimes values are looked up from two tables before that calculations are performed. Here is a basic example of one of the queries:

FROM History
                             FROM ATTRIBUTES
                             WHERE (P1 = @P1 AND P2 = @P2 AND P3 = @P3))

I have many such queries, most of which are identical to the one above execept EXACT is replaced with different column names.  The variables @GAME, @EXACT, @ P1, @P2, and @P3 are all in Linked to individual dropdownlists.  I've been returning each of the queries results to its own seperate dropdown list as well.  This may not be the best way to display the data as there will be at least 80 seperate dropdown lists (each containing only a sing value), although this will easily produce all the info new info I need. Now, the question is: how can I save the selected values of each of those drop down lists by clicking a single button? When I say "save the selected values," what I want to do is combine them all into a single table row and insert it to a specific table.


1/26/2008 4:33:12 AM 91979 articles. 3 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 39

If you have all the drop dow lists on the same page, you can traverse all of them and combine the selected values in a single string.

For example,

string values = ""; 

foreach(Control c in Page.Controls)


if (c is DropDownList)


DropDownList ddl = DropDownList(c);

values += ddl.SelectedItem.Text;



Umair Hafeez Mughal
Asst. Software Engineer
Virtual University of Pakistan


Please remember to click “Mark as Answer” on the post that helps you.
1/26/2008 6:42:07 AM

Actually I was hoping to somehow connect a simple SQL insert statement to a single button. Supppose I had the following statement:


All of the @ variables are the selected values of several different dropdown lists. I just want to add a single button that will perform that statement. Im not sure how to connect the buttons properties to do this. Any help would be appreciated.  


1/26/2008 3:53:31 PM

Assuming that this code goes behind in the .aspx.cs file....this might get you want you want.... 

VALUES("'"+DropDownList1.SeletedItem.Text+"', '"+DropDownList2.SelectedItem.Text+"', '"+..........and so on....)

This statement goes along with  SqlCommand statement...which goes inside the button1_click event.....


Hope tat helps...


Thou who knows not that he knows not is a fool, shun him.
Thou who knows that he knows not is a child, teach him.
Thou who knows not that he knows is asleep, awaken him.
Thou who knows that he knows is a leader, follow him.
1/26/2008 6:18:54 PM

thanks, I'll give that a try


1/27/2008 2:31:29 AM

Similar Artilces:

Cascading Dropdown List
Hi, First post so hello and need some help with an issue I have been dealing with.  I have an intranet page I created in ASP.NET using C# .NET 3.5 with a few Ajax Extenders including 3 Cascading Dropdown Lists. Now I have used the Cascading dropdown lists for my own purposes i.e they do not actually cascade their results to another dropdown list, the reason I did this was due to the having a User Control that contains an update panel and other bits i.e I didn't want the control/page posting page (something that happens when you click on a regular dropdown list). Everything is wor...

dropdown selected value and dropdown no value saved
 is there any way the selected value is selected already when i try to edit the gridview ... and another thing... when i edit this dropdown.. no value was being saved... what is wrong or missing.. please help... i almost spend two days on this problem...i've read many post about this.. but still i didn;t get it... please help///  <asp:TemplateField HeaderText="Unit" SortExpression="UnitID">                          &...

Password text value gets deleted when value selected from Dropdown list
Hi, I need help in my dropdown control, this is what my problem is I am using DropDown List in my aplication in a form and i want to show some default selected value in the first drop down D1 and depending on values selected in D1 the values gets displayed in the child drop down D2. My issue is i have a password texbox before getting valued from D1 and D2......when i select value from D1 the password enetered in hte password textbox in password mode gets deleted. so every time he user types the password and then select something in the dropdown, he has to ...

get list of databases into dropdown, and selection of database display related tables
Hi All, iam doing one web application, i have 2 dropdown list boxes, in 1st dropdown should display all sqlsever databases. based on selction from dropdown(database), display the related tables in 2nd dropdown. plz help coding how to do. thanks. Ram.  Hi. In SQL Server you can do this: --list the databases EXEC sp_databases --get all the user-created tables & views in 'MyDatabase' SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG = 'MyDatabase' My Blog hi booler, how to write database connection in to get all database...

getting value 1 from a selected checkbox & saving the value into a database
Hi, I m new to ASP... I m building a page with few checkboxes & text boxes.. its a simple checklist you can say.. However, what i am looking for is when a check box is checked & the submit button is clicked, the value of that checkbox as 1 should be saved in the database. How to acheive this... any help would be really appreciated... Thanks Aadil  in the buttons click event look and see if the check boxes are checked and save in the db if so  if(chk1.Checked) {         //save in db      }Mike Starkey MCP, MCTS Hi Aadil you c...

How to get value from first dropdown list to second dropdown list
Hi Does soneone know hot to get value from first dropdown list to second dropdown list or remove it from seond dropdown list? I have a web form page. On the page, there are two dropdown lists, one Add button, and one Remove button . First dropdown list has four list items. Second one does not have list item yet. When select a item from first dropdown list, then click "add" button. I want it to apear in the second dropdown list without reload the page. Or select item from second dropdown list, and click "Remove" button. it will remove from second list. Please help. &nb...

Selected value in select list with javascript based off value in database
 I've got a classic asp page with a select list. I need the select list's selected value to be whatever the user selected when they created their account. I've been trying to use <body onLoad="onLoad();"> to call my function, and then I'm trying to specify which value should be selected in the function. Also, when the select list selected values change, there is a javascript function I call to disable text boxes. I think there is an issue with my javascript function, and I can't find any examples of this from good ole' google.  My j...

How to use values from two dropdown lists to get the value for a third dropdown?
I have three dropdown lists.  One for Office, one for Department, and a list of employees.   There is no relationship in the database between office and department.  The relationships are to the employees.  What I need to do is take the selected values from Office and Department, and run a query to get the list of employees who match both parameters (Office & Department).  Here's my code for the three dropdown lists.  How do I "connect" Office & Department to populate employees?  code from my page    for the ...

Populate dropdown list based on selected value in another dropdown list
I have a datagrid (grdCar) that contains two dropdown listboxes (ddlCarManf and ddlCar). When the user clicks the "Edit" link and places the grid into edit mode, they select a value in ddlCarManf. Based on the selected value in ddlCarManf, I need to then populate ddlCar with a list of cars for which the selected manufacturer makes (I'm using ddlCarManf.SelectedValue to query the database).  I bind my datagrid in the page_load event as: If Not Page.IsPostBack Then    BindGrid() End If Here is my control (ddlCarManf) as is appears within grdCar in ...

How do i save selected items on dropdown list to database?
Hi guys,I have 3 dropdown list for Month, day, and year; an SqlDatasource and a Save button....can you teach me how to save selected items from the dropdown lists to the database?  IN the Save button click event get the selected values from the ddls and send them to teh database like below, protected void Button1_Click(object sender, EventArgs e)    {        SqlConnection con = new SqlConnection("Data Source=NUSRV-prj;Initial Catalog=PFM_TestDB;Integrated Security=True");        SqlCommand ...

Selected value of a dropdown list, submit to database.
Hi. I have a dropdownlist that I populate from a database (works).  When a user selects a value in the list and submits, the page gets reloaded with the values that are left in the dropdownlis (minus the one that was just submitted).  The submission works fine if the user goes down the list top to bottom, one by one until everything is gone.  However, if the user say selects the third item in the list and submits, it still submits the top item instead. Which of course causes issues. I am setting the value of the item to submit as ddl.selectedvalue... whats the issue? Sourc...

How do I insert the selected value from a dropdown list into my database?
My question is: How do I insert the selected value from a dropdown list into my database? This is really frustrating!!  My drop down list is populated by a states.xml I just want to be able to insert the selected value of my dropdown. Here is my page: <%--<asp:TextBox ID="MailingStateTextBox" runat="server" Text='<%# Bind("MailingState") %>' Visible="False" />--%> MailingState:<asp:DropDownList ID="MailingStateDropDown" runat="server" DataSourceID="XmlDataSource1" DataTextField=...

Get all values from database if no dropdown item is selected ?
HiIn my web application, i use some dropdown lists and a submit button to filter a gridview on another pagestr = "res.aspx?ddl1=" + ddl1.SelectedItem.ToString + "&ddl2=" + ddl2.SelectedItem.ToStringResponse.Redirect(str)I'd like to get all values from the database if no item is selected from the dropdown lists .What should the SQL look like for the select in the sqldatasource ?Thanks.  What you can do is send 0 to the parameter in stored procedure if dropdown value is not selected. and in the stored procedure just put a if condition to get the appropriate d...

Dropdown with saved value selected, but other options listed?
I've created a page that a user enters data thru various databound dropdown lists and text boxes.  When the user clicks submit, the data is stored in various tables.  My question is, what if the user made a mistake and wants to return to a page that looks similiar to the page that they entered data.   How do I display the value they entered as the selected value of the dropdown box, but still provide them with all the other selections for the dropdown box so they can change their entry?  Never make important decisions on a Monday! This really depe...

Web resources about - Saving DropDown List Selected Values to database? -

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

Dodgy database exposes details of 191 million US voters
... years, there's a high chance that your personal details are now out in the wild. Security researcher Chris Vickery found a misconfigured database ...

Huge database of 191 million U.S. voters found on the open Internet
... such bulk information online, a recent discovery seems to indicate. According to VentureBeat , a security researcher found the exposed database ...

3.3 million Hello Kitty fans' details have been exposed in a huge database leak
... week after week, the hacks, breaches and data leaks continue to roll in. The latest victim? Hello Kitty. CSO Online is reporting that a database ...

Under pressure, DNC restores Bernie Sanders campaign's access to their database - Videos - CBS News
A strange twist in the race for the democratic presidential nomination: the campaign of Vermont Senator Bernie Sanders has filed a complaint ...

Massive Voter Database Left Open For Public Consumption
Gosh, we could have avoided all the angst about the Clinton/Sanders voter database breach if only we'd known about this major database , accessible ...

Database configuration issues expose 191 million voter records
A misconfigured database has led to the disclosure of 191 million voter records. The database, discovered by researcher Chris Vickery, doesn't ...

Botched database leaks records for 191 million voters
... sometime this century? If so, your personal info may be out in the open. Researcher Chris Vickery has discovered that a badly configured database ...

191 Million US Voter Registration Records Leaked In Mystery Database
A huge database of 191 million US citizens is uncovered. But no one knows who carelessly left it open, whilst the FBI have been contacted.

Resources last updated: 1/3/2016 2:26:30 AM