metropia
asked on
how to access listview values on edit, and pass them to stringbuilder
Hello,
Would someone help me figure out how to correct the error on the subject of question?
My code is:
Then that error goes away but then i get a Object reference not set to an instance of an object.
I think each on of these fields are empty (nothing)
TryCast(item.FindControl(" ProcessTyp e"), TextBox)
TryCast(item.FindControl(" AdditionOr der"), TextBox)
Please any help would be much appreciated.
Would someone help me figure out how to correct the error on the subject of question?
My code is:
Private Sub lvRecipeSteps_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles lvRecipeSteps.ItemCommand
If e.CommandName = "Update" Then
Dim myContext As New OLTPEntities
Dim item As ListViewItem = e.Item
Dim tbx As TextBox = TryCast(item.FindControl("Recipe_IdTextBox"), TextBox)
Dim strRecipeId As String = String.Empty
strRecipeId = tbx.Text
Dim myRecipeStepsHistory = myContext.RefineRecipeStep.Where("it.Recipe_Id=" & strRecipeId).FirstOrDefault()
Dim strRefineRecipeStepRecord = New StringBuilder("")
If myRecipeStepsHistory IsNot Nothing Then
' Recipe_Id
strRefineRecipeStepRecord.Append("Recipe_Id: " & myRecipeStepsHistory.Recipe_Id & ", ")
' Recipe_ProcessType
If Not String.Equals(myRecipeStepsHistory.ProcessType, TryCast(item.FindControl("ProcessType"), TextBox)) Then
strRefineRecipeStepRecord.Append("ProcessType: Old= " & myRecipeStepsHistory.Recipe_ItemNumber & ", New= " & TryCast(item.FindControl("ProcessType"), TextBox).ToString() & ", ")
End If
' AdditionOrder
If Not String.Equals(myRecipeStepsHistory.AdditionOrder, TryCast(item.FindControl("AdditionOrder"), TextBox)) Then
strRefineRecipeStepRecord.Append("AdditionOrder: Old= " & myRecipeStepsHistory.AdditionOrder & ", New= " & TryCast(item.FindControl("AdditionOrder"), TextBox).ToString() & ", ")
End If
' Log Update
Dim strId As String = Me.dvRecipeItem.DataKey(0).ToString()
Dim strModifiedBy As String = System.Web.Security.Membership.GetUser.UserName.Trim
Dim myAppLog As New AppLogClass(inEventCode:="Update",
inItemCode:=strId,
inDetailCode:=Membership.GetUser.UserName,
inDescription:="Recipe Step Updated By: " & strModifiedBy,
inNote:=strRefineRecipeStepRecord.ToString())
myAppLog.Save()
End If
End If
End Sub
Then that error goes away but then i get a Object reference not set to an instance of an object.
I think each on of these fields are empty (nothing)
TryCast(item.FindControl("
TryCast(item.FindControl("
Please any help would be much appreciated.
Can you show the aspx code?
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
let me try that!
ASKER
It worked indeed.
ASKER
right on target.
thank you very much CodeCruiser!
thank you very much CodeCruiser!
ASKER
I would like to extend a little bit on this question.
When I do the e.Command = "Delete" does not work like it does for the Update.
Perhaps is due to the value coming from a different template?
I tried changing it like this:
I get an Object reference not set to an instnnce of an object message again
Dim myRecipeStepsHistory = myContext.RefineRecipeStep .Where("it .Recipe_Id =" & Me.lvRecipeSteps.FindContr ol("Recipe _Id").ToSt ring()) << this line
When I do the e.Command = "Delete" does not work like it does for the Update.
Perhaps is due to the value coming from a different template?
I tried changing it like this:
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 instnnce of an object message again
Dim myRecipeStepsHistory = myContext.RefineRecipeStep