Solved

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

Posted on 2014-10-04
7
425 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
  • 4
  • 3
7 Comments
 
LVL 33

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 33

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Closing Comment

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

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 33

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

13 Experts available now in Live!

Get 1:1 Help Now