Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

load page controls with recent added item

Posted on 2014-01-30
18
Medium Priority
?
280 Views
Last Modified: 2014-02-05
I would like to request for help.

I am able to Edit, and Delete items from a combination of drop down list (driver)
details view (parent), list view (children)

What I need help with is when an new item gets inserted at the parent level.

I would like to re-run the code that loads the drop down list using the newly added item, thus being this one the one that is displayed in the details view, list view (children rows are optional right now)

I am attaching a copy of my vb.net code so far. and aspx

PLease let me know if this is enough information
vb.net.txt
aspx-code.txt
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
  • 12
  • 3
  • 3
18 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39823858
>What I need help with is when an new item gets inserted at the parent level.

Can you show the code that does this?
0
 

Author Comment

by:metropia
ID: 39823950
it is using the details view default insert event.

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

so that the drop down gets reloaded with the new value in the list, but i need to have the new value as the selected value after it gets inserted from the details view.
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1400 total points
ID: 39824088
When a user adds an item to the list, store that item in a session variable...
     Session("NewListItem") = strNewListItem
...then, when you rebuild the list, set the list's SelectedItem to the value of the session variable...
    ddlList.SelectedItem = Session("NewListItem")

This is only pseudocode, but it should get you started.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:metropia
ID: 39824116
I have a question, the key field is Id, and that field is hidden when the details view is on edit mode. When the record is added to the database, the Id value is auto-generated. Only then I will have access to the value, otherwise it does not exist on the form/ page/ detailsview

Seems to me that what I have to do is, after the record gets added, pull its Id, the assign this value to a variable like you said:
    Session("NewListItem") = strNewListItem
and then use the variable to do the part:
    ddlList.SelectedItem = Session("NewListItem")

Due to my lack of expertise, I am unsure under which event will I be able to pull the new id for the new record? so that I can later use it as described above

I hope this makes sense, if not, please let me know. I can post more bits of the code.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 600 total points
ID: 39824227
Is DisplayName (which you are using as DataTextField for dropdown) unique? If it is, you can get this value for newly inserted record in the ItemInserted event and then use it to select the item in drop down list.
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1400 total points
ID: 39824253
Yes, if the new item is going into a database, and that database is being re-queried to populate the list, you could perform an extra step, get the id of the item when you add it to the database, then select the id in the list instead of the name.  This would be better if you have/may have multiple items with the same name.
0
 

Author Comment

by:metropia
ID: 39824282
yes, there will be only one display name per  item (ideally) haven't debug the app enough to make sure that duplicates aren't being inserted.
0
 

Author Comment

by:metropia
ID: 39824288
How will I get the Item Id after gets inserted if I am using the default event form the detailsview? will it be possible to see some code example?

will i put thge re-query code in the

dvRecipeItem_ItemInserted
Or
dvRecipeItem_ItemInserting

thank you
0
 

Author Comment

by:metropia
ID: 39824333
I tried this

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

    Dim Id As Integer = Convert.ToInt32(e.Values("Id"))
    lblMessage.Text = Id.ToString    
End Sub

Open in new window


But I get zero.

When I checked the database, I see that the new record id is actually 46.
0
 

Author Comment

by:metropia
ID: 39824373
I think I got it

    Protected Sub dvArticulos_ItemInserted(sender As Object, e As EntityDataSourceChangedEventArgs) Handles EntityDataSource_RecipeItemDetail.Inserted
        Dim last_Id As Long = DirectCast(e.Entity, RefineRecipe).Id
        'Session("Articulo") = last_Id
        lblMessage.Text = last_Id.ToString
    End Sub

Open in new window

0
 

Author Comment

by:metropia
ID: 39824386
I would like to ask for help, now that I am able to access the last id inserted, to learn how to reload the drop down with the new id selected.


if helps to get your assistance, here is the aspx code of the drop down list:
                        <asp:DropDownList 
                            ID="ddRecipeItemNumber" 
                            runat="server" 
                            width="600px" 
                            DataSourceID="EntityDataSource_RecipeItemNumber" 
                            DataTextField="DisplayName" 
                            DataValueField="Id" 
                            AutoPostBack="True"
                            OnDataBinding="Page_Load"
                            CssClass="cssRecipeItemNumber">
                        </asp:DropDownList>
                        <asp:EntityDataSource 
                            ID="EntityDataSource_RecipeItemNumber" 
                            runat="server" 
                            ConnectionString="name=OLTPEntities" 
                            DefaultContainerName="OLTPEntities" 
                            EnableFlattening="False" 
                            EntitySetName="vStd_RefineRecipe" 
                            EnableDelete="True" 
                            EnableInsert="True" 
                            EnableUpdate="True" 
                            EntityTypeFilter="vStd_RefineRecipe" 
                            Where="It.Id > 0"
                            OrderBy="It.ItemNumber">

Open in new window

thank you
0
 

Accepted Solution

by:
metropia earned 0 total points
ID: 39824418
perhaps this:

    Protected Sub dvRecipeItem_ItemInserted(sender As Object, e As EntityDataSourceChangedEventArgs) Handles EntityDataSource_RecipeItemDetail.Inserted
        Dim last_Serie As Long = DirectCast(e.Entity, RefineRecipe).Id
        lblMessage.Text = last_Serie.ToString
        ddRecipeItemNumber.DataBind()
        ddRecipeItemNumber.SelectedValue = last_Serie.ToString
    End Sub

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39824608
Yes that should reload the drop down list. Does that work?
0
 

Author Comment

by:metropia
ID: 39824618
yes it works!
0
 

Author Comment

by:metropia
ID: 39824626
I have a question. After I insert the new record, and if I refresh the page (browser refresh button) then the record gets inserted again.

How can I stop this from happening?
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 39824675
On postback, clear the data that does the insert, once the insert has been completed.
0
 

Author Comment

by:metropia
ID: 39824678
Paul,

"clear the data that does the insert"


Would that be?

EntityDataSource_RecipeItemDetail
0
 

Author Closing Comment

by:metropia
ID: 39835083
This is the code that worked for me in the end.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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