ClientSide error checking before submit

Posted on 2006-04-21
Last Modified: 2008-02-26
I have a column in a datagrid that I want to check to see a sequence.

The column can contain X number of items. They are integer values that represent a sequence.

So something like


I want to give them the ability to change the sequence, but I need to ensure that there are no duplicates. Each has to be unique. Is there a way for me, when they click the submit button to check if there are duplicates, and if it is, pop up a message. Since it is a datagrid, I might even process it on the server, and then send a message back saying sorry but they arnt unique. I know how to parse through the datagrid on the server side. Just need the logic and code either client or server to do a constraint check.



Question by:Term56
    LVL 6

    Expert Comment

    Try using a loop to count the distinct values in a column, then you could use a second loop to extract the rows with counts greater then 1.

    Public Function GetDuplicates(ByVal table As DataTable, ByVal field As
    String) As DataTable
            Dim hash As New Hashtable
            For Each row As DataRow In table.Rows
                Dim key As Object = row(field)
                If hash.Contains(key) Then
                    hash(key) = CInt(hash(key)) + 1
                    hash.Add(key, 1)
                End If

            Dim clone As DataTable = table.Clone()

            For Each de As DictionaryEntry In hash
                If CInt(de.Value) > 1 Then
                    For Each row As DataRow In
                        table.Select(String.Format("{0}='{1}'", field, de.Key))
                End If
            Return clone
    End Function

    Then you can use it something like:

        Dim myTable As DataTable
        Dim duplicates As DataTable
        duplicates = GetDuplicates(myTable, "Zip")


    Author Comment

    so let me understand, for each pass through GetDuplicates, it takes one item, goes through the table, and determines if there are 2 of the same kind ?

    Author Comment

    solved it myself

    Private Function Sequence_Correct()
            Dim dgItem As DataGridItem
            Dim strdgItemToAnalyze As String
            Dim dgItemLoop As DataGridItem
            Dim intCounter As Integer = 0
                'Loops through each item in the datagrid to ensure there are no duplicate entries
                For Each dgItem In dgList.Items
                    strdgItemToAnalyze = CType(dgItem.Cells(0).FindControl("Sequence"), DropDownList).SelectedValue
                    'Checks to see if there is more than 1 instance of any sequence
                    intCounter = 0
                    For Each dgItemLoop In dgList.Items
                        If CType(dgItemLoop.Cells(0).FindControl("Sequence"), DropDownList).SelectedValue = strdgItemToAnalyze Then
                            intCounter += 1
                        End If
                    If intCounter > 1 Then
                        'If there is more than one instance, return false
                        Return False
                    End If
             'If it reaches here, means there are no duplicates
              Return True
    End Function

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    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 …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    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…

    779 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

    16 Experts available now in Live!

    Get 1:1 Help Now