metropia
asked on
load page controls with recent added item
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
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
ASKER
it is using the details view default insert event.
i just added
Private Sub dvRecipeItem_ItemInserted( sender As Object, e As DetailsViewInsertedEventAr gs) Handles dvRecipeItem.ItemInserted
ddRecipeItemNumber.DataBin d()
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.
i just added
Private Sub dvRecipeItem_ItemInserted(
ddRecipeItemNumber.DataBin
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
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
will i put thge re-query code in the
dvRecipeItem_ItemInserted
Or
dvRecipeItem_ItemInserting
thank you
ASKER
I tried this
But I get zero.
When I checked the database, I see that the new record id is actually 46.
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
But I get zero.
When I checked the database, I see that the new record id is actually 46.
ASKER
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
ASKER
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:
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">
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes that should reload the drop down list. Does that work?
ASKER
yes it works!
ASKER
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?
How can I stop this from happening?
On postback, clear the data that does the insert, once the insert has been completed.
ASKER
Paul,
"clear the data that does the insert"
Would that be?
EntityDataSource_RecipeIte mDetail
"clear the data that does the insert"
Would that be?
EntityDataSource_RecipeIte
ASKER
This is the code that worked for me in the end.
Can you show the code that does this?