metropia
asked on
how to access listview value on delete command
I would like to ask for help regarding an asp page with a list view.
I want to get the Id value for the selected row, so that I can query the entity framework, get the record and delete it.
Down below is the code for when I do the e.Command = "Delete"
Dim myRecipeStepsHistory = myContext.RefineRecipeStep .Where("it .Recipe_Id =" & Me.lvRecipeSteps.FindContr ol("Recipe _Id").ToSt ring()) << this line, I thinkis because I am not looking for the right control?
I have attached a copy of my aspx code. Hopefully some one will be able to provide guidance on this problem.
Thank you much.
listview-aspx-code.txt
I want to get the Id value for the selected row, so that I can query the entity framework, get the record and delete it.
Down below is the code for when I do the e.Command = "Delete"
If e.CommandName = "Delete" Then
Dim myContext As New OLTPEntities
Dim myRecipeStepsHistory = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & Me.lvRecipeSteps.FindControl("Recipe_Id").ToString())
Dim strRefineRecipeStepRecord = New StringBuilder("")
If Not IsNothing(myRecipeStepsHistory) Then
' Recipe_Id
strRefineRecipeStepRecord.Append("Recipe_Id: " & Me.lvRecipeSteps.FindControl("Recipe_Id").ToString() & ", ")
I get an Object reference not set to an instance of an object, message.Dim myRecipeStepsHistory = myContext.RefineRecipeStep
I have attached a copy of my aspx code. Hopefully some one will be able to provide guidance on this problem.
Thank you much.
listview-aspx-code.txt
What event are you using to do the delete? The ListView Deleting event passes a Keys collection as part of it EventArgs. That collection will include the ID of the row being deleted.
ASKER
I started using:
defined, but I have not been able to figure out how to access it and then query the Entities.
Private Sub lvRecipeSteps_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles lvRecipeSteps.ItemCommand
And then check the Command Name: If e.CommandName = "Delete"
I now changed the code to use ItemDeleting event, because I have a DataKeyNames="Id" defined, but I have not been able to figure out how to access it and then query the Entities.
Private Sub lvRecipeSteps_ItemDeleting(sender As Object, e As ListViewDeleteEventArgs) Handles lvRecipeSteps.ItemDeleting
Dim myContext As New OLTPEntities
Dim myRefineRecipeSteps = myContext.RefineRecipeStep.Where("it.Id=" & Me.lvRecipeSteps.DataKeys().ToString()) << this does not work
ASKER
I am still not able to make it work. I hope you can offer some help.
I really need it.
Thank you
I really need it.
Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.