ClientSide error checking before submit

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.



Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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")

Term56Author Commented:
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 ?
Term56Author Commented:
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
PAQed with points refunded (500)

Community Support Moderator

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
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

From novice to tech pro — start learning today.