Solved

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

Posted on 2014-10-04
7
446 Views
Last Modified: 2014-10-05
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!
0
Comment
Question by:Brad Aberg
[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
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40361768
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
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40361774
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
 

Author Comment

by:Brad Aberg
ID: 40361810
This is great.  Thank you very much eghtebas (Mike).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Brad Aberg
ID: 40361811
Thanks!  This was my first question on Experts-Exchange.  I appreciate your detailed answer.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40361813
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
 

Author Comment

by:Brad Aberg
ID: 40362482
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
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40362715
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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