DropDownList selected item is not correct in updating

I have a DetailsView1 tied to SqlDataSource3.  There is a DropDownList, dlPlant, in a template in one of the rows in edit mode.  When the user clicks the Update link, I try to catch the selected value of dlPlant in SqlDataSource3_Updating.  However, I find that the selected value in SqlDataSource3_Updating is not the value the user has selected while in edit mode, but always the intial value at the time the DetailsView1 was entering the edit mode.  Why is this so?

My code is as follows:

protected void SqlDataSource3_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
  
DropDownList dl;
   dl=(
DropDownList)DetailsView1.FindControl("dlPlant");
  
Page.Title = dl.SelectedValue;

 Is this the right method to find out the selected value of a DropDownList in edit mode?

 Thanks.

0
hc1
10/31/2008 1:57:15 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
614 Views

Similar Articles

[PageSpeed] 43

can you check if the drodownlist's autopostback property is to "true"?

alternatively, you may use the dropdownlist's SelectedItem.Value property to determine the value.

as stated above, how is the dropdownlist populated? is it by design time or runtime... are there values bound to the dropdownlist's  item text and item value properties?


Clicking “Mark as Answer” would also help other community members reading the thread.


"Two roads diverged in a wood, and I—; I took the one less traveled by, And that has made all the difference. -The Road Not Taken"
0
praetorean
10/31/2008 3:14:49 AM

AutoPostBack is false.

I checked and SeletedItem.Value is the same as .SelectedValue.

My drop down list is populated inside its Load event handler.  The initial value is also set inside there.  I checked and the Load event was called only once, presumabley when the DetailsView entered the edit mode.

0
hc1
10/31/2008 7:27:25 AM

I solved it. The problem goes away if I populate the drop down list in its DataBinding event rather than the Load event.

Thanks.

0
hc1
10/31/2008 10:26:04 AM
Reply:

Similar Artilces:

how to populate a dropdownlist control and update the selected item in a gridview control
Hi friends help me with this ... Requirement: 1) i want to populate a dropdownlist(ddl) in a gridview when clicking the edit button of a perticular row by using gridview events and also update the selected item of the ddl to the database. 2) also i don't want to use sqldatasource controls i.e. we should take the help of only gridview events 3) DropDownList will be populated fom TableB: Actions taken: In page_load while binding the grid i m getting the error: Cannot perform '=' operation on System.Int32 and System.String  my fields and datatypes are as follows...

dropdownlist: select selected item during update
Hi, I have a datalist (databound) with notes ralated to persons. (Every note has one person). When I want to update a note, there is a drop downlist with al persons from the database (databound). The dropdownlist is created during the OnDataBind event of the datalist. But I want to select the previously selected person in the dropdownlist. (probably with dropdownlist.SelectedIndex). That is when the personID from the note is the same as the personID in the onDataBind of the dropdownlist. protected void dlLogboek_Ondatabind(object sender, DataListItemEventArgs e) { DropDownList ddlCpers...

updating label text based on selected item in a DropDownList (LINQ, VB.NET)
Hello experts,Quick question for you: I'm writing a form that loads an XML file as an XDocument and populates the items in a DropDownList based on a field in the XML structure.What I would like to do is change the text on certain labels in the form based on what is selected in the DropDownList. I've got the first part of this down, but am having trouble getting the label text changed. Any assistance you can give me is appreciated.Here's the XML file: <Errors> <SubErrorCode> <Number>-82</Number> <ErrMsg>Lorem</ErrMsg> <WIH>I...

After selecting DropDownList Item, how to set DropDownList Item so that it corresponds to new selection.
Hi,  I'm having difficulty retaining DropDownList selected item so that it corresponds to the new page that is called when the item is selected. i.e DropDownList contains 4 Items Item1 Item2 Item3 Item4 Each item when selected is bound to a corresponding page. Item1.aspx Item2.aspx Item3.aspx Item4.aspx If the default page is Item1.aspx...if I select Item3 in the DropDownList, the page Navigates to the corresponding page - Item3.aspx.  I want the DropDownList to remain displaying Item3 and not the default Item.  Thank you. for master pag...

When to select items in a dropdownlist control?
I have a DropDownList that loads its data from a SqlDataSource. Right after the data has been loaded into the DropDownList, I want to programmaticaly go in and make a selection based a QueryString ID. So the question is, when do I start executing my code to make selection of the DropDownList items? After you are done with loading the dropdownlist with data from the database.Thanks,MaxLet Me Google That For You! I know that, but where exactly is the event handler or method that I will need to put my code in? So you don't load it programatically. If thats the case, did you try Page_LoadT...

Dynamic DropDownList Default Selected Item Does Not Select Default Item
I have some dynamic listbox code that creates a listbox based on information stored in a database. The database access works fine. The only issue is that when I use the lbNew.Items.FindByValue(...).Selected = True line, no default select is made. The listbox just defaults to the first item in the list.lbNew = New DropDownList ' Scans for the list source. ' If "values_table" returns the first character = '@', ' then a table is the datasource. strDataSourceTable = Nothing strDataSourceTable = objDataReader.Item("values_table") ' If there is a data list, display the item, else ig...

How to display the more than one row with items and buttons in gridview control. when i select three items at same time from categories(Fruits, Apples, Gifts). The selected items are displayed in g
Hi,when i select three items at same time from categories(Fruits, Apples, Gifts). The selected items are displayed in gridview.Here i would like to change this way "when i click more than one category at same time. it should be display selected item and button."For example: if i have to select Fruits, Apples from categories.  it should be display like 1st "row have Fruits and In 2nd row have Apples and button" in gridview.the button have some event.How can i do it? Please can anyone answer me.With kind requestThanks your query is very raw..can u details it out...Pl...

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

Which Validator control to check that an item is selected in a DropDownList?
I have a DropDownList with say the following 5 items: -- Department -- Operation Engineering Sales Which validator control can help to check that an item other than the 1st one is selected?   Thanks, Ben  Just add a normal RequiredFieldValidator but set the InitialValue attribute to the text of the ListItem that you want prevent from being selected. Here is an example:  <asp:DropDownList AppendDataBoundItems="True" ID="JobTypeDropDownList" runat="server" SelectedValu...

Updating a part of a FormView with several controls by a DropDownList selection
I have a complex list/detail page. I need to update the info at several detail fields when I select a option from a dorpdownlist. To ilustrate the problem consider the following example (not the actual data but fits): Imagine a page to manage Car/Motor info. So you have a list of Cars at the left and when you select one the detail form at the right side is filled with the Car info. One of the fields is the Motor. (the table Car has a foreingkey to the table Motor; 1 - N relationship); At the motor panel when you select the Motor id/name at the DropDownList the several motor info ...

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

DropDownList in DetailsView to update selected item in another DetailsView
I've got a DropDownList in a DetailsView that is used for an order form (inserts a record). When the user selects an item in the DropDownList, I want another DetailsView to advance to the record associated with the selected item so that the user can see more details on the item they are going to order. I am able to get the second DetailsView to update when I select a new item in the DropDownList only when I take it out of the first DetailsView. When I put it inside the DetailsView I get this error:Exception Details: System.InvalidOperationException: Could not find control 'ddItems' in Cont...

HOW TO PROGRAMATICALLY SET THE SELECTED ITEM IN A DROPDOWNLIST WEB CONTROL
i have a datagrid and a dropdownlist (that has a value of male & female) as my edititemtemplate. i'd like to have the value of a cell(e.g female) serve as the default value of a dropdownlist after i click the edit button on a datagrid. any idea? try this with your controls Private Sub mygrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles mygrid.ItemDataBound If e.Item.ItemType = ListItemType.EditItem Then Dim mydropdown As DropdownList = CType(e.Item.FindControl("id of your control"), Dropdow...

Need to update a listbox from selection in dropdownlist, both controls in EditItemTemplate of datalist
I select a record from the datalist, this opens the EditItemTemplate. In this section I have a dropdownlist, when I select a value from this dropdownlist I would like to populate a listbox (also in the EditItemTemplate) with the values relevant to the selection made in the dropdownlist. Thanks....

Web resources about - DropDownList selected item is not correct in updating - 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: 12/7/2015 6:25:35 PM