Solved

how to access listview values on edit, and pass them to stringbuilder

Posted on 2014-01-28
7
412 Views
Last Modified: 2014-01-28
Hello,

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    

Open in new window


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("ProcessType"), TextBox)
TryCast(item.FindControl("AdditionOrder"), TextBox)


Please any help would be much appreciated.
0
Comment
Question by:metropia
  • 5
  • 2
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Can you show the aspx code?
0
 

Author Comment

by:metropia
Comment Utility
attached there is the aspx code only the listview part.

thanks a lot.
reciper.aspx.txt
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Try changing these lines

TryCast(item.FindControl("ProcessType"), TextBox)
TryCast(item.FindControl("AdditionOrder"), TextBox)

To

TryCast(item.FindControl("ProcessTypeTextbox"), TextBox)
TryCast(item.FindControl("AdditionOrderTextbox"), TextBox)
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:metropia
Comment Utility
let me try that!
0
 

Author Comment

by:metropia
Comment Utility
It worked indeed.
0
 

Author Closing Comment

by:metropia
Comment Utility
right on target.

thank you very much CodeCruiser!
0
 

Author Comment

by:metropia
Comment Utility
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:

        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() & ", ")

Open in new window

\

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.FindControl("Recipe_Id").ToString())  << this line
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now