dropdownlist: select selected item during update


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 ddlCpersoon = (DropDownList)e.Item.FindControl("ddlCpersoon");

if (ddlCpersoon != null)


SqlConnection connection = new SqlConnection(connectionString);
SqlParameter param;
SqlDataAdapter daDdlCpers;
DataSet dsDdlCpers;

daDdlCpers = new SqlDataAdapter("sprocSelectDropDownCpersonen", connection);
daDdlCpers.SelectCommand.CommandType =
param = daDdlCpers.SelectCommand.Parameters.AddWithValue(
"@bedrijfsID", intBedrijfsID);
param.Direction =
dsDdlCpers =
new DataSet();
ddlCpersoon.DataSource = dsDdlCpers.Tables[
ddlCpersoon.DataValueField =
ddlCpersoon.DataTextField =


12/5/2005 2:08:31 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 18

After binding the Dropdownlist put,

 ddlCpersoon.SelectedValue = [previous value];



6/14/2007 10:45:29 AM

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

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

Why is the select saying selected after an item is selected?
This was a whitelisting issue due to a software upgrade at hostgator..  Nothing wrong with my code..Scot King SEO Software Tool | Search Engine Optimization"Get your page rank high"  huh? It is smart to put your question in the body and not just in the title. Have no idea what your question is or if it even a question.Eric Pascarello.com | Twitter epascarello | LinkedIn use thisddl.options[ddl.selectedIndex].selected = false; //Clear the selection ddl.options[1].selected = trueMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Sit...

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 do I select an pre-selected dropdownlist item?
I have a dropdownlist for which I want to select the item previous selected, and the item id is a request.querystring item. How do I do that? dim selecteditem as string selecteditem = request.querystring(".....") dpTest.Items.FindByValue(selecteditem).Selected = True***********************Dinakar NethiLife is short. Enjoy it.*********************** Thanks !...

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

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

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

Selecting the items in a CheckBoxList control that are already selected
Simple problem here.  I’ve not used a CheckBoxList control in an ASP.NET application before (ASP.NET 3.5 in this case), and now I need to.  Databinding it to the source to populate the items of the list is easy.  However, selecting those items which are already stored in the database; I’m not sure how I can do that with databinding. So the question is, how do I databind the items in the CheckBoxList which reflect the items already selected in the database, in this case in a resolution table between the data items table and the lookup table, so that I get what’s in the res...

Setting DropDownList Selected Item from dbase SELECT
Hi! I've searched everywhere for the answer to this problem, but I can't seem to find the answer. I'm making an edit page for a user to edit their profile. One of the fields is a DropDownList containing a list of states (the states is populated from a database call to a lookup table). I want to match the state the user has in their profile to the appropriate state in the drop-down, and make that item selected. Unfortunately, I can't find any examples on how to do this. Also, since the drop-down control is within a repeater control (to populate the fields), it makes it even more diffi...

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

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

Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, daniel_AT_infrontsoftware_DOT_com@N0SPAM.com says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

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

Web resources about - dropdownlist: select selected item during update - asp.net.presentation-controls

Resources last updated: 12/30/2015 3:39:45 AM