Solved

drop down list databind with new item inserted in detailsview

Posted on 2014-01-30
3
812 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
Comment Utility
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
Comment Utility
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
Comment Utility
"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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Encryption Decryption in Oracle 12 59
How do I get the id from URL? 19 47
.Net Web Site Password specs 2 20
Achieve json result 2 28
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now