Solved

drop down list databind with new item inserted in detailsview

Posted on 2014-01-30
3
813 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

16 Experts available now in Live!

Get 1:1 Help Now