Dropdownlist not posting back selected values.

My data base looks like this. My dropdownlist has the vacancy_num as the DataTextField and  description as DataValueField. If I select a vacancy_num and do a post back to place the 'description' name as a label using the DataValueField for the value, The vacancy_num ALWAYS selects the first vacancy_num in the sequence.

Example: I choose B1000/2. Postback returns B1000/1. I choose B4000/3, postback returns B4000/1. Why does it not keep the value I selected?? I have noticed that if I replace the DataValueField to point to the vacancy_num it works fine. But then I don't have a description. I am using a SqlDataSource. Please Help me.

vacancy_num                                        description                                       
------------------------- --------------------------------------------------

B1000/1                                            BD Northern England
B1000/2                                            BD Northern England
B4000/1                                            BD West Midlands & Cheshire
B4000/2                                            BD West Midlands & Cheshire
B4000/3                                            BD West Midlands & Cheshire
B7000/1                                            BD N London & E Anglia
H1335/1                                            Client Services
L2221/1                                            Progress to Work/Linkup Berkshire

2/15/2006 12:13:58 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 49

When dropdownlist have duplicate DataValueField , it will always select the first one.

One of  solving this is use index while loading dropdownlist

DropDownList1.Items.Insert(2,new ListItem("DataTextField ","DataValueField"));


here "2" is the index..

You can access DataTextField by using Selected Index.

Other way is instead of SlectedValue , choose SelectedText



Hope it helps..


My Blog

"Don't be afraid to be wrong; otherwise you'll never be right."
2/15/2006 2:38:43 PM

Similar Artilces:

Changing Selected item of a dropdownlist when posting back from other control
Hi, I have several controls in an asp.net web form, including a dropdownlist. When I do a postback from one of the controls (not the dd list), I want to change the content of the dd list (this goes ok), but I also want to change the selected item in the list. In the code, setting the selected item seems to work (though the debugger I see it sets the selected item correctly), but when I look at the html there is NO ITEM SELECTED in the dd list!! How is this possible?? I'm totally confused. By the way, all actions are happening in the Page_Load. It's probably a viewstate problem or...

Trouble getting selected value from DropDownList when posted back
I have a DropDownList inside a Repeater with AutoPostBack=True. I need to get the selectedvalue of the DropDownList so that I can populate another DropDownList based on its value. I was trying to do this in the Page_Load method but the value is coming back as null. Here's what I was trying. What am I doing wrong? Thanks <asp:DropDownList ID="OfficeDDL" runat="server" AutoPostBack="true" /><br />  if (Page.IsPostBack) { DropDownList OfficeDDL = (DropDownList)EmployeeOfficeAddressRepeater.FindControl...

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

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

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++)        {            // obtain category id and name            categoryId = productCategories.Rows[i]["CategoryId"].ToString();            categoryName = productCategories.Rows[i]["Name"].ToString();            // populate the list boxes            categoriesListAssign.Items.Add(new ListItem(categoryName, categoryId));        }   ddl button click    protected void assignButton_Click(object sender, EventArgs e)    {            //Request the product ID from the query string            string pr...

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(asp.net) is that, when i select Supplier _ it reloads the page and i loose the values in that combo box...i have heard of postback method but i donno how to use it to implement the same. please any one send me answer..   Hello friend,  Yes, for sure you're experience this error because of the postback. You are populating the dropdown with data on the page_load event, correct? If so you just have to do it on the first time, because the ViewState will mantain the date between postbacks. To do this is quiet simple, just had this code over the code where you populate your main drop down:if(!IsPostBack) { //your code goes here }Hope it helps!!!  ...

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

Select dropdownlist control value
Hi, 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 ...

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

How to post selected Id from dropdownlist to a controller
 Hi,I'm having trouble sending a selected Id from my dropdownlist in the View over to a Controller called 'PassedValue'.  When I click the buton to submit nothing happens.  When I view the html source it looks like like this: <form method="post" action="/Home/PassedValue" > <select id="Country" name="Country"> <option value="1"> Uk</option> <option value="2">USA</option> <option value="3"> France</option> <option va...

Value of DropDownList without post back
I have a DropDownList populated by an ArrayList (manually filled). I want to capture the SelectedIndex value of the DropDownList at form submission. All attmepts have left me with the first value of the list, and not the selected item. Is it not possible to get this value to change without the _OnSelectedIndexChange event on postback? M A common cause of this is re-binding the dropdown in PageLoad on every postback. That causes the user's selection to be overlayed before the page processing cycle reaches the point where your postback events are processed. Check "If Not Is...

Dynamic control post back value
*** edited by: master4eva *** Please enclose your code in < code ></ code> tags (without the spaces). This will make your code easier to read online; therefore, encouraging a response to be faster. It is to your own benefit for your question to be answered in future. I have already done the editing to include the < code ></ code> tags for this post. ********* I'm builidng a dynamic page with server controls inside a table based on data from sql table. While myReader.Read() Dim lbl2 As Label = New Label lbl2.ID = "l...

Not able to select value from dropdownlist control
I used sql server database with the multiple table connectivity. I created view to join three table and created stored procedure to fill dropdownlist control. I filled dropdownlist control succesfully but I am not able to select value from dropdownlist either by selectedItem.value or selectedItem.text. It selects first value only. <asp:TableCell VerticalAlign="Top"> <asp:DropDownList ID="NewDistNameNo" Runat="server" Width="100%" DataTextField="dist_name_no" DataValueField="office_id" AutoPostBack="True&quo...

Option to have no value selected in DropDownList control?
Whenever I DataBind a DropDownList, the list is already defaulted to a default value. I would like to user to have the option of not choosing anything from the dropdown list. The first line of the dropdown should be "-- Select --" or something similar. How can I accomplish this? When the user submits the form, no value should be passed for that input... I just can't get this to work at all. after binding the records from your database into your dropdownlist, add this code: DropDownList1.Items.Insert(0, "-- Select --") DropDownList1.SelectedIndex = 0 mes...

dropdownlist's selected index value is not printing the selected value
Here iS my code .Aspx Page <asp:DropDownList ID="ddlkeyword" runat="server" Width="204px" DataTextField="Form" DataValueField="Form" OnSelectedIndexChanged="ddlkeyword_SelectedIndexChanged" >   </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="Submit" Width="110px" OnClick="Button1_Click" /> my aspx.cs protected void Page_Load(object sender, EventArgs e) { fillddlkeyword(); }protected void Page_Init(object sender, EventArgs e) { ...

Menu control : Cross page posting and posted values in nested controls?
I've created a dyrnamic template for a menu control which renders either a textbox or a linkbutton. The textbox acts as an search input field. The value of this field then acts as input to another page(on another frame actually). What happens is that clicking on the linkbutton will do a postback to Main.aspx(which resides in a frame called 'MainWindow'). When the value arrives at Main.aspx, I see the value from 'searchMovies' textbox posted into the Request.form collection as : 'NavigationMenu$ctl05$searchMovies' with the value that was keyed in. From main.aspx, does anyone know...

Hi all, i am using C# , asp.net vs2005. ajax 1.0 i am populating data programitically . when i select first value, dropdown control select the same. when i select second value ,dropdownlist select second value too But i does not continue  from third value onward . when i select third value, dropdownlist control select second value then after behavior reman the same no matter what i select dropdownlist control select second value ONLY.<asp:DropDownList id="Ddlzse" runat="server" Width="165px" Font-Bold="False" Fo...

Problem in Using DropDownList Control to select a selected row of SqlDataSource that is under GridView Control
Hi all,In my SQL Server Management Studio Express, I have a database "ChemDatabase" that has a table "LabData"  formatted in the following way: SampleID int PRIMARY KEY, SampleName nvarchar(25), ChemicalName, nvarchar(25), Concentration decimal(6.2) with 5 rows of records in this .dbo table. In my Visual Web Developer Express, I created a website "RPD-TCE" for extracting a row of record from the LabData table by using a DropDownList, a GridView and a SqlDataSource.  I want to click DropDownList to list one number of S...

Selected Value of DropDownList within a wizard control
Hello: Within the wizard there is a ddl that when a certain value is selected an action will be performed. I have read at least 50 posts by others with similar difficulties, but none with solutions that work for me. here is what I have so far:     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)    {         UserControl objCtrl = ((UserControl)(FindControl("Wizard1")));        DropDownList ddl = ((DropDownList) (objCtrl.FindControl("DropDownList1")));  &n...

Which Validation control to ensure a value in dropdownlist is NOT selected ?
I have a dropdown list with allowable values like this but I wish to force them to select something:- Pls SelectUSUKFrance I want the user to select US, UK or France but not 'Pls Select' Which validation control I should use and how I should set it ? Thanks  Thanks in advance for the help. I will try to credit the ones who helped but most important is we really do sincerely thanks to all who have helped.  Use RequiredFieldValidator and set its RequiredFieldValidator.InitialValue Property as "Pls Select" (or value property of "Pls Select"...

Hi how to fire a dropdown which is binded inside a gridview control ..as the binding took place in rowdatabound column,now i want that when i select an item from the dropdownlist,few gridcells shd populate with data ...on which event should i write and how... Thanks... You can design a function where u want to do some processing say functionXYZ. Now in PageHTML View where dropdown is declared in GrdiView u can do like that:<asp:DropDownList id='DropDownListID runat=Server autopostback=true enableviewstate=true OnSelectedIndexChanged="functionXYZ"> functionXYZ u ca...

binding selected value to dropdownlist in repeater control
I am trying to bind the SelectedValue of a dropdownlist in an itemtemplate of a repeater control.  The problem is that some of the values I'm binding to are not in the dropdownlist.  I want to say if the field I'm binding to is not in the list, don't bind and just select the first item as usual, otherwise bind.  Where and how would i say that.  I've tried binding using <%#Bind()%> and that doesn't look like it's going to work.  Thanks for all your help. Dear, friend: Would you plz dump some codes here?  Best Regards,__________________________________________________Sincerely,Rex LinMicrosoft Online Community SupportIf there is any question or the issue is not resolved, please feel free to mark the thread as not resolved Let me try ot explain a little better what I'm doing.  I have a database column that I am binding to a dropdownlist.  Some of the values in the database column are null.  When a value is null, i don't want the dropdownlist to bind, I just want it to select the first item in hte list as normal.  If I do something like <asp:dropdownlist id=Something SelectedValue='<%#Bind("thiscolumn")%>' it works as long as the value exists in the list.  Basically I don't want it to do anything if the value doesn't exist.  Is there some event where I can get the item the ddl is binding to and check for nulls and cancel the binding? the easiest way is to filter the data on database le...

User Control DropDownList Selected Value Not Passed
Edited by SomeNewKid. Please post code between <code> and </code> tags. Hi, I'm using C#. I have a user control DropDownList (SearchCategory.ascx) that when included on my page (index.aspx) will not pass the selected value to a simple function in script tags of head content on a button click. It just passes the first value of the list no matter what is selected. I need to pass to the function (in the script tags of head content of index.aspx) the value of a text box (works fine cause it is not a user control) and the value of the DropDownList (only passes the first...

Web resources about - Dropdownlist not posting back selected values. - asp.net.presentation-controls

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: 3/5/2016 10:15:16 PM