Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ClientSide error checking before submit Asp.net/Vb.net

Posted on 2006-04-21
5
Medium Priority
?
262 Views
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

1.
2.
3.
4.
5.
6.
7.

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.

Thanks.

Cristian.



0
Comment
Question by:Term56
  • 2
4 Comments
 
LVL 6

Expert Comment

by:JRossi1
ID: 16508432
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
            Else
                hash.Add(key, 1)
            End If
        Next


        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))
                    clone.ImportRow(row)
                Next
            End If
        Next
        Return clone
End Function


Then you can use it something like:


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


0
 

Author Comment

by:Term56
ID: 16509189
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 ?
0
 

Author Comment

by:Term56
ID: 16641722
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
                Next
                If intCounter > 1 Then
                    'If there is more than one instance, return false
                    Return False
                End If
            Next
         'If it reaches here, means there are no duplicates
          Return True
End Function
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 16826293
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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