Solved

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

Posted on 2014-01-28
7
420 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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