Dropdown with saved value selected, but other options listed?

I've created a vb.net 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 vb.net 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!
12/9/2008 1:54:31 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 31

This really depends on how you are displaying your data. If you are programmatically data-binding your data to a single DropDownList, then within the DataBound event handler of that control you can set the SelectedIndex. Otherwise, if you are using a FormView or a DetailsView, then you can simply add a data-binding expression to the SelectedValue property of your DropDownList so that the value is automatically selected for you.

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

12/9/2008 2:02:06 PM

Bind the dropdown list as normal, but set the selectedvalue to the value that has been stored in the database.


If this answered your question, please mark as an answer so others will know too.

12/9/2008 2:03:18 PM

ecbruck - I'm not using Form View or Details view, instead I'm programmatically binding.    So, do I basically need to have two datasources?  One to get all the values that are available, and one to get the value that the user selected?  If that's the case, how do I tell the first datasource that the selected value is equal to the second datasource?   

This is one of my dropdown boxes where I tell the database to go and get all the possible Client Types.  

<asp:SqlDataSource ID="getBusType" runat="server" ConnectionString="<%$ ConnectionStrings:xxx %>" SelectCommand="sp_GetBusType" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:DropDownList ID="BusType" runat="server" AppendDataBoundItems="true" DataSourceID="getBusType"DataTextField="busdesc" DataValueField="bustype">
<asp:ListItem Text="Please select Client Type..." Value="" />

Never make important decisions on a Monday!
12/9/2008 2:09:51 PM


 You need to bind the controls again with the data as you did on the first page  and then access the selected value using the Previous Page Property

For example me.PreviousPage.TextBox1 in VB.Net to get the value selected in previous page

MAKMark as Answer if this reply helps you
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
12/9/2008 2:11:09 PM

First off, in the future may want to consider one of these controls just for simplicity. Otherwise, I'd use your SqlDataSource simply to populate the DropDownList. Then, programmatically, within the DataBound event handler of the DropDownList, retrieve the SelectedValue from your data source, and then set the SelectedIndex of your DropDownList accordingly.

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

12/9/2008 2:17:13 PM

hmmmm.trying to think this thru.....  so, I have the new.aspx page that they input all their data and they click save... Do I need to create a totally separate  update.aspx page where they can see what the entered and make changes and click update, or is there some way (if/then) to do bind the dropdown and IF there is a value, have it be selected? 

Never make important decisions on a Monday!
12/9/2008 2:20:50 PM

I'm not really the one to ask for this, but your users are. Do THEY want you to do everything within the same page? If so, I'd really consider moving over to a FormView or DetailsView.

If you do need to do this manually, then you can certainly check for the existense of a value and then set it if necessary.

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

12/9/2008 2:29:06 PM

mudassarkhan - There isn't a previous page, as all the questions are on one page.  is there another way to bind the value? 

Never make important decisions on a Monday!
12/9/2008 2:35:58 PM

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">                          &...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

can i drag the selected value of dropdown list in one web part to another web part
hi, supose i am having time displaying in on webpart can i drag the value of time to another web part and and display the time is: and the value draged from the other webpart so i want to drag the value year and population into antoher web part and according to that the grap must appear i.e what  i exactly want is i must drag some value from one webpart to onother webpart and according to event some thing must happen in another web part   Hi, The problem has been replied in the following post: http://forums.asp.net/t/1141884.aspx But from the title you described, do ...

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 ...

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 u...

Drop down list in Form view returns error when value in bound field (data binding
I get the following error when I click edit to edit the details in the web form:'ddlUserRestrictionType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value  I would like it to accept any value which currently exists in the database. Is this easily achievable? With what you've posted, all I can tell is that you are trying to set the SelectedValue of a ddl to a value that does not exist in the list.  It would be helpful if you can post some code and the expected values of this control.~ Timwww.bucketo...

Sorting microsoft report on web form from dropdown list values
Hi, I have a Microsoft report viewer tied into an object data source. The object data source is pointing to a data table .xsd file. I have setup my filtering using parameters in SQL and tying those parameters to controls on my web form to filter the report. That is working fine, however I also want to be able to use a dropdown list to select the fields to sort the report by, as well as what order ascending or descending.  I know you cannot use parameters in the Sort By column in SQL so I have been trying to use the SORT BY CASE statement then pointing those parameters to the dropdowns...

About dropdown list selected item and selected value
hi to all i have one table. that have albhapetic list of countries name and country id. i want to bind country table to dropdownlist. dropdownlist text field is country name the value field country id.the dropdown list heading is "-- select country--". but page load time i want load default country is INDIA and value is ind. guide me how achieve this scnario. You can write following line in Page load event.ddCountryDropDownList.SelectedValue = "ind";Hope this helps! Programmers are tools for converting caffeine into codeVisit my blog Try this way insteadDropDown...

adding values to the selected value in Dropdown list
 Hi,   I have dropdown box in my page which have some value inherted from the another list box in my page..Now in my second page , i have dropdown box with values and text value and list box... I'll be selecting the one value from the dropdown then i enter the value in text box and click on add button which will add the value in the list box like this i can able to add many value...now if i click on save button for the selected dropdpown item the added values in the listbox should be saved ...like this i add many values for many dropdown item and saved respectivelynow if c...

How to show value in textbox from selected value in Dropdown list
I have two text box, txtbox1 should be from two field for example i have one dropdownlist where i select item and another txtbox2 i want to put value, when i first time to write manually value in txtbox2 in and selected item from ddl i want to result in concatenate from in txtbox1. for example  I haveif not me.ispostback thenDim cm as new sqlcommand("Select AccMjrid, Names from Accgrp", me.sqlconnection1.open())me.sqldataAdapter1.fill(Dataset1, "Accgrp") Me.cmbAccMajID.DataSource = Me.DataSet11.Tables("AccMajor") Me.cmbAccMajID.DataTextField = "AccName" Me.cmbAccMajID.DataValueField ...

DropDown list submits first value not the selected value
I am relatively new to programming and am having a problem with a small project that I am working on.  I have a names drop down list that is created from a database.  When the user selects a name and completes the rest of the form and clicks submit.  All of the data they entered is submitted to a different table in that database.  This is workign correctly for all of the data except the drop down.  For some reason the first value in the drop down is being submitted each time.  Here is the code and any help you can give will be appreciated. Public Class final1 ...

Dropdownlist selected value passes first value in list no matter what value is selected. why ?
 HI . I have a dropdownlist. Databinds ok but when I must pass a value as a Selected value it always passes the first value in the list even if I select another value. I tried to set the ddl to enableviewstate false but it doesn't change anything. Any ideas ? Code below, thanksLoading the ddl:       productCategories = CatalogAdmin.Admin_Product_Categories_NotIn(productId);        for (int i = 0; i < productCategories.Rows.Count; i++)        {       &...

Populating and Implementing 4 Dropdown lists on web form through web service
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which contains information About CustomerName, CustomerType, Address, City. These 4 colum values should populate the 4 Dropdown lists. And then I need to implem...

Web resources about - Dropdown with saved value selected, but other options listed? - asp.net.web-forms

How to convert unordered list into nicely styled <select> dropdown using jquery?
$('ul.selectdropdown').each(function(){ var select=$(document.createElement('select').insertBefore($(this).hide(); $('>li a', this).each(function(){ ...

Credit Suisse Reiterates On Enbridge Energy Partners, L.P. Following Alberta Dropdown
In a report published Thursday, Credit Suisse analyst John Edwards reiterated an Outperform rating on Enbridge Energy Partners, L.P. (NYSE: EEP), ...

Convert a Menu to a Dropdown for Small Screens
Create a menu that, on smaller screens, changes into a dropdown menu. A dropdown takes up much less screen real estate and can be easier to use. ...

Office-Add-in-Fabric-UI-Sample/Dropdown-demos.html at master · OfficeDev/Office-Add-in-Fabric-UI-Sample ...
Contribute to Office-Add-in-Fabric-UI-Sample development by creating an account on GitHub.

Google Adds Dropdown Menu to Search Results, Hides Cached Pages Inside
Google recently updated their search results format, again moving the link for cached page access somewhere else. Now it hides in a convenient ...

50+ Awesome jQuery Dropdown Menu Tutorials
When designing graphical user interfaces, many people prefer to use a dropdown menu as a GUI element. This allows the user to choose a value ...

Sign out command in dropdown
We can save some space in the menus by putting the Sign-out command in the dropdown menu. As we're building the menu, if I see a command called ...

Google toys with removing Instant Preview in Search, adds dropdown menu with Cached, Similar, Share options ...
Google has added a new drop-down menu to its search results page beside every URL with three options: Cached, Similar, and Share. At the same ...

Facebook Fan Page Changes You Haven’t Heard About
... fashion appears at the top center of the page if you scroll down to the cover image or any point lower. A box labeled highlights has a dropdown ...

Edit Companies - Eric Feng - CrunchBase Person Profile
If this person is an investor, please only submit companies for which he/she has a functional role (like Board, Advisor, etc). Click 'Past?' ...

Resources last updated: 12/21/2015 2:32:52 PM