Solved

drop down list databind with new item inserted in detailsview

Posted on 2014-01-30
3
822 Views
Last Modified: 2014-01-31
On my page I have two object data sources; the first has a bound drop down
list, with an item number and a description. The second has a bound details view showing
everything for the item number.

Selecting an item in the drop down list, causes the details to be shown, as
intended. When I insert a new record from the details view, I want to add it
to the drop down list and select it.

I tried to just do a:

Private Sub dvRecipeItem_ItemInserted(sender As Object, e As DetailsViewInsertedEventArgs) Handles dvRecipeItem.ItemInserted
    ddRecipeItemNumber.DataBind()
End Sub

And even though Databind does load the newly added item to the drop down list, it does not make it the selected value, thus the record displayed on the details view is just whichever item number is first since it is ordered by item number

can some one explain me how to make it work for the scenario i described on the second paragraph?

thank you very much.
0
Comment
Question by:metropia
3 Comments
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 250 total points
ID: 39823455
You must select the item manually.

ddRecipeItemNumber.DataBind()
ddRecipeItemNumber.SelectedValue = ...

You can use e.Values to obtain a dictionary with the field name/value pairs for the inserted record. Then set the SelectedValue property of your DropDownList to the appropiate value.

Hope that helps.
0
 
LVL 12

Accepted Solution

by:
jitendra patil earned 250 total points
ID: 39823458
hi

as you said
even though Databind does load the newly added item to the drop down list, it does not make it the selected value

unless and until you provide a  selected value to the dropdownlist it will display the first coming record only.

you need to assign a selected value to the droplist and accordingly update the details view also.

to do that you can have a newly added value in a public variable on .vb page and assign the selected value of dropdown with the variable value.

now again rebind your detail view wih the selected value of dropdownlist.

hope this helps.
0
 

Author Comment

by:metropia
ID: 39824146
"You can use e.Values to obtain a dictionary with the field name/value pairs for the inserted record. Then set the SelectedValue property of your DropDownList to the appropiate value."

Would you be able to show me how to do this?

Thank you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question