Select dropdownlist control value


I have created a dropdownlist dynamically and populated it with numbers from 1 to 10. I also have a submit button on my page which when clicked is supposed to get the number I have selected in my dropdownlist. But this does not happen.
It keeps returning 1 even if I select 4. I'm guessing whenever the page is loaded the dropdownlist is being created again and hence it selects the first number which is 1.
Can anyone tell me how to solve this problem? How do I get the value of the number I have selected from a dropdownlist which is created dynamically?
Thanks in advance for your suggestions.
9/2/2003 12:59:00 PM 91979 articles. 4 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 1

Is the code that loads up the data into the dropdownlist run EVERY page_load, or are you doing so only if IsPostBack==false?

Starting with ASP.NET 2.0? Look at:
Programming Microsoft Web Forms
My Blog
9/2/2003 1:17:37 PM

I'll explain what i'm doing. I know about the IsPostback.
I have a dropdownlist which has values such as Fruits, Vegetables etc in it. When I select fruits I dynamically create a table with the name of the fruit and dropdownlists for each fruit containing quantity from 1 to 10 and display it on the page. If I select vegetables then it will show me vegetables The details for the fruits and vegetables are coming from a database.
So for example:
If I choose Fruits from the initial dropdownlist I will be shown this:
No Fruit Quantity(dropdownlist)
1. Apples 1 - 10
2. Oranges 1 - 10
3. Mangoes 1 - 10
So after I choose 4 from the Apples dropdownlist it gives me 1 instead of 4 as it is being recreated again.
I hope you understand my problem.
9/2/2003 1:31:38 PM

This is what i'm trying to do. I'm explaining in more detail.
1) In my page I have a dropdownlist which has categories such as fruits, vegetables etc. I set the autopostback property to true for the dropdownlist. The different categories come from a database.
2) On selection of the fruits category I use the selectedindexchanged of the dropdownlist and then query a database to get a list of fruits. After I get these details I create a table to display the fruits and on the right of each fruit I have a quantity dropdownlist which contains values from 1 to 10. This quantity dropdownlist is created dynamically.
3) So now if I select 4 from the quantity dropdownlist for apples I should be able to display "You have selected 4 apples".
Unfortunately this does not happen. I always get 1 apple.
I will send you the code if necessary.
9/2/2003 1:48:17 PM
Hi Yoshi,

I"m facing same problem . Did you find the solution? If yes please let me know.
Here is the link :

If you have any solution please let me know.
9/4/2003 7:59:14 PM
send the code...
Christian Calderon
Need to work in Classic ASP? then do it the right way with CLASP!
Classic ASP Framework
9/4/2003 9:06:04 PM
I think since you make the control dynamically you will have to query the Request object because the control will submit it's value but it is not getting handled by the viewstate so when you rebuild the ddl, check for its value in the Request object and set in manually.

Hope that helps...
C# / C++ Developer
9/4/2003 11:17:30 PM

That's one solution, but it's probably not the best. You shouldn't have to read the Request directly.
Dynamically created controls are more difficult to persist, but it can be done. The key to this is timing: all controls have to be recreated on each postback before the page framework restores the states from posted values and viewstate. That is, you have to recreate and populate controls during Init.
Does this help?
This posting is provided "AS IS" with no warranties, and confers no rights.
9/5/2003 12:02:07 AM
bleroy ,

Can you please give me some example how i can do this. It would be great help for me. or if there is any other way to to do this. I have posted my code above if you can give me some tip how can i recreate and populate control during Init?
Thanks ,
9/5/2003 12:19:09 AM
In your example, from the event handlers that currently fill the other lists, you could store the current mode into the ViewState.

Then, on subsequent postbacks, you should test this viewstate value from the OnInit event end refill the lists accordingly.
Does this help?
This posting is provided "AS IS" with no warranties, and confers no rights.
9/6/2003 12:56:35 AM

Similar Artilces:

how to get selected the value of cascading Ajax dropdownlist extendar control after postback.
how to retain value of dropdown list after postback which is extended by ajax cascading dropdownlist extendar. thanks in advance.     Hi, Can you further elaborate your problem? your retain value is for nxt drop down list? how many drop down list you have? normally what we trying to retrieve value from selected dropdown value is Label1.Text=DropdownList1.selectedValue :) Regards, Hideyoshi, hi,i have 2 Ajax dropdownlist Which is filed through web service. one filter the other.the second dropdown has value <-All->,a,bwhen i select a and cl...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

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++)        {       &...

how can i Fill the controls on web page by selecting value from dropdownlist control.
  Hi,  Currentlly i am working on a web application where i require to fill the web form with the selected item in a text box. for example i have dropdown control named supplier_name, and i want to fill all the other controls values from database on the form when i select name from that supplier_name box,i.e , if i select name1, then related to that name, its code,address ,city should appear on related text boxes. I have done the same in windows application with c# , but the problem with web application( is that, when i select Supplier _ it...

how to get SELECTED VALUE of parent dropdownlist to target dropdownlist using cascading
Hi All, I am using C# , asp.net2.0 , Ajax1.0 i am filling dropdownlist using cascading ajax extender. i taken help of ajax site and build a code to fill the control. my question is how do i get parent selected item value. my web service code to fill target value public CascadingDropDownNameValue[] GetProd(string knownCategoryValues , string category) {StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //string subgrp ; //int sub1; //if (!kv.ContainsKey("Prod") || !Int32.TryParse(kv["Prod"], out sub1)) //// if (...

Getting DropDownlist's DataTextValue Selected Value Given the SelectedValue and/or Selected Item
In the codebehind, I need to extract something from the Text (displayed) value of dropdownlist's selected item and I have  the SelectedValuand and SelectedItem in hand. How can I do this?  FindControl? Item? row?   Thanks. Well, its easier than you might think. SelectedItem has a "text" property. Thats the selected text right there :)  If you need the Text of the selection, then you have to use the SelectedItem.Text property.  If you want the value (not the displayed text) the you can directly use the SelectedValue. dim sText as String = dropdown...

Getting Selected Value from DropDownList
Hi All, I'm trying to get a selected value from a dropdownlist after a submit button is pressed but keep getting the following error: Object reference not set to an instance of an object (that old chestnut!) Ok, here is the way my code is set up: I have a control called Attributes (Attributes.ascx and Attributes.ascx.vb) Attributes.ascx Here I have a dropdownlist whose id is "DataDownTest". Attributes.ascx.vb Here I have, amongst other things, this code: Protected WithEvents DropDownTest As System.Web.UI.WebControls.DropDownList Public ReadOnly Proper...

Getting The Selected Value of a DropDownList
I have a DropDownList that is populated with selections from a database on the page load event. It displays fine with all the correct values, BUT there is a problem when I try to process its data. I eventually reference the DropDownList during a button's server click event. I want to know which value is selected, and I am trying to do so with a call to: DropDownList.SelectedItem.Value; The problem is that such a call is alway referencing the first item of the list, not the one the user selects. What am I doing wrong? In your page load event handler do you put data bind code ins...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateComm...

Dropdownlist not getting the selected value ...Help
Hi, I am creating a simple data entry form with web matrix, which will insert records to my access database. I am having more than 5 dropdownlists with data coming from tables in the databae.They are databound. I have a dropdownlist called Workarea1.I would like to populate the list from the database .But after selecteing the value from the dropdown, I click the save button, then the VALUE IN THE DROPDOWNLIST IS DEFAULTED TO THE FIRST RECORD. My code looks like this. I have tried the page.ispostback condition too...but does not seem to work My code looks like this Sub Pag...

Getting selected value of calendar control
  I'm trying to set the selected value from a calendar control to a parameter to pass to a stored procedure. I cannot get the value set. I can't even get it to display in a label. Any help is appreciated. Thanks! My code... protected void MyCalendar_SelectionChanged(object sender, EventArgs e) { SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnConnectionString"].ConnectionString); // create a command object identifying // the stored procedure SqlCommand cmd = new SqlCommand(&q...

Getting a dropdownlist selected (text) value
Alright, I give up! I've been researching this all day with no luck, although I know there's a solution. I am trying to get the Text value of an item that I selected from a dropdownlist. For example, if I've got a list that would display: SELECT YOUR FAVOURITE COLOR: DROP DOWN LIST NAME = favColor COLOR_ID | COLOR ----------------------- 1 | RED 2 | BLUE 3 | GREEN I'm obviously able to pull the integer (COLOR_ID) out of the list by using the Request.Form("favColor"), but how can I get the COLOR value/text/name?...

Web resources about - Select dropdownlist control value -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/22/2015 10:15:57 AM