ASP.NET : How to highlight differences between two form views with the same text boxes between them

I have two FormViews on a web page:  One shows a row of data (fields, columns) from a database table, the other the same row of data.  The difference between them is that one of the FormViews show one or more fields that a user changed (Updates to the record).  I want to highlight in one or both of the FormViews, which pair(s) of the same fields are different between them.

Example:

FormView1.................................................FormView2
Name: Joe                                                Name: Joe
Phone Num: 800-999-9999                  Phone Num: 888-999-9999
etc.                                                            etc.

I would like to highlight the phone number because it's been updated.  The real FormViews will have many fields so it's not easy for someone looking at the two FormViews to spot any changes unlike in the trivial example above.

How to approach this problem or some code (VB or C# is ok) would be appreciated. Thanks!
Brad AbergDatabase AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
Recently, I used a similar concept in my application. This was for a WinForm but I am sure it could be adapted for use in asp.net (vb.net), declare:    

'To  initialize with the 2nd column textbox control names and their matching value pairs (in not postback)  
Dim dataPair As New Dictionary(Of String, String)  

'To  initialize with the 2nd column textbox control names and True (in not postback)                      
Dim boldataPairMatching As New Dictionary(Of String, Boolean)  

Form this point on, you caan revise the following winform code to suit your needs (in postback):
   Private Sub TestRevised(sender As Object, e As EventArgs) Handles FirstNameTextBox.TextChanged, LastNameTextBox.TextChanged, AddressTextBox.TextChanged, _
         CityTextBox.TextChanged, StateTextBox.TextChanged, ZipCodeTextBox.TextChanged, PhoneTextBox.TextChanged, EmailTextBox.TextChanged

        Try

            ' find if any of the text boxes has be modified
            ' to enable/disable btnSave accordingly
            Dim bolSaveYN As Boolean = False
            Dim txt As TextBox = TryCast(sender, TextBox)

            If bolSaveNew Then Exit Sub

            If bolChangeText = True Then
                If dataPair.Item(txt.Name) = txt.Text Then 'same as old value
                    boldataPairMatching(txt.Name) = True
                Else
                    boldataPairMatching(txt.Name) = False
                End If
            End If

            For Each pair In boldataPairMatching
                If pair.Value = False Then
                    bolSaveYN = True
                End If
                ' MessageBox.Show(intEdits & ", " & dataPair.Item(txt.Name) & ", " & txt.Text)
            Next

            Me.btnSave.Enabled = bolSaveYN

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

Open in new window

Mike
0
Mike EghtebasDatabase and Application DeveloperCommented:
Below, I tried to modify to suit your need. But it needs more massaging:
  
        Try
            ' somehow, store text boxt control just edited in txt
            Dim txt As TextBox = TryCast(sender, TextBox)

            ' compare to see the value is the same
            If dataPair.Item(txt.Name) = txt.Text Then 
                boldataPairMatching(txt.Name) = True    'same for txt
            Else
                boldataPairMatching(txt.Name) = False   'not the same for txt
            End If

            ' loop thru
            For Each pair In boldataPairMatching
                If pair.Value = False Then
                   'remove the red border
                Else
                   'make border re
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

BTW, this is how I initialized my dictionary variables:
       Try
            ' first time FirstNameTexBox gets focuses dataPair gets intilized and
            ' bolLoadDictionaryYN gets set to false to prevent updating dataPair dictionary
            If bolLoadDictionaryYN Then
                dataPair.Add("FirstNameTextBox", Me.FirstNameTextBox.Text)
                dataPair.Add("LastNameTextBox", Me.LastNameTextBox.Text)
                dataPair.Add("AddressTextBox", Me.AddressTextBox.Text)
                dataPair.Add("CityTextBox", Me.CityTextBox.Text)
                dataPair.Add("StateTextBox", Me.StateTextBox.Text)
                dataPair.Add("ZipCodeTextBox", Me.ZipCodeTextBox.Text)
                dataPair.Add("PhoneTextBox", Me.PhoneTextBox.Text)
                dataPair.Add("EmailTextBox", Me.EmailTextBox.Text) 'boldataPair

                ' with intial bolChangeText = false to prevent text box change event  
                ' firing when the form gets first uploads 
                boldataPairMatching.Add("FirstNameTextBox", True)
                boldataPairMatching.Add("LastNameTextBox", True)
                boldataPairMatching.Add("AddressTextBox", True)
                boldataPairMatching.Add("CityTextBox", True)
                boldataPairMatching.Add("StateTextBox", True)
                boldataPairMatching.Add("ZipCodeTextBox", True)
                boldataPairMatching.Add("PhoneTextBox", True)
                boldataPairMatching.Add("EmailTextBox", True)
            End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brad AbergDatabase AdministratorAuthor Commented:
This is great.  Thank you very much eghtebas (Mike).
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Brad AbergDatabase AdministratorAuthor Commented:
Thanks!  This was my first question on Experts-Exchange.  I appreciate your detailed answer.
0
Mike EghtebasDatabase and Application DeveloperCommented:
Do you mind sharing your solution? I am sure there are lots I could learn from you. In particular, I want to to know how you got control names? etc.

Thanks,

Mike
0
Brad AbergDatabase AdministratorAuthor Commented:
Mike,

My code is pretty simple and basic because I am a beginner at ASP.NET.  Here's a snippet showing comparison of one pair of textbox text contents.

Protected Sub SqlDataSource3_Load(sender As Object, e As EventArgs) Handles SqlDataSource3.Load
    Dim foo As TextBox = TryCast(FormView1.FindControl("LastNameTextBox"), TextBox)
    Dim bar As TextBox = TryCast(FormView2.FindControl("LastNameTextBox"), TextBox)
    If foo IsNot Nothing Then

      If bar IsNot Nothing Then

        If foo.Text <> bar.Text Then

          bar.BackColor = Drawing.Color.Yellow
          foo.BackColor = Drawing.Color.Yellow

        End If
      End If
End Sub

Open in new window


Tomorrow I am going to see if I can use your more sophisticated answer to improve my code.  The way my code is n ow, I'll have to include lines for every pair of textboxes in the formview (about 35 or so).  If I can use to loop through I will have a more elegant solution. Thanks again.
0
Mike EghtebasDatabase and Application DeveloperCommented:
Oh, I thought you already have it finalized. Yes looping through the text boxes is the way to go.

If you decided to post a new question on the text boxes, add a link here so I could post a solution.

Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.