Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-28
7
Medium Priority
?
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 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