Solved

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

Posted on 2014-01-28
7
416 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
ID: 39816471
Can you show the aspx code?
0
 

Author Comment

by:metropia
ID: 39816515
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
ID: 39816540
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:metropia
ID: 39816698
let me try that!
0
 

Author Comment

by:metropia
ID: 39816722
It worked indeed.
0
 

Author Closing Comment

by:metropia
ID: 39816724
right on target.

thank you very much CodeCruiser!
0
 

Author Comment

by:metropia
ID: 39816912
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

25 Experts available now in Live!

Get 1:1 Help Now