Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

drop down list databind with new item inserted in detailsview

Posted on 2014-01-30
3
Medium Priority
?
844 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 1000 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 13

Accepted Solution

by:
Jitendra Patil earned 1000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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