datagrid-how to check for duplicate values in rows?

hi

i have a datagrid , and in one of the columns i have a column application..where i have values
like below:

APP
APP
DEV
DEV
APP
NEW
NEW

i want that if the column value is being repeated then i dont display anything.

how is the feasible?
thanks
monikadangAsked:
Who is Participating?
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.

jyotisinhaCommented:
This is possible but the datasource need to be sorted on the column Application....you will have to code into ItemDatabound event of Datagrid with following logic-

declare a variable at class level. preserve the value of current record in this variable and check if next record has same value or not. if yes then don't print anything else print the value.

this 'll work BUT I'd suggest to do this(suppressing the duplicate row in same column) in datasource or if posssible then in the query that's populating the datasource.

HTH,
Jyoti.
itcnbwiseCommented:
This would best be done by altering your SQL query - please post that source.
monikadangAuthor Commented:
here is my datagrid event

Public Sub bindGrid2()
            Try
                'CheckValidate
                Page.Validate()
                If Not Page.IsValid Then
                    Return
                End If
                'get details from the db
                GoToDBOpenConn()
                strSQL = "select FILEID, FILENAME,APPICATION,LOCATION,FILEREPORT, DESCRIPTION, location2 FROM DOWNLOADFILES WHERE (@lower(ORGANISATION)=@lower('" & Orgn & "')) and FILEREPORT='REPORT'  order by APPLICATION, FILENAME "
                objCommand = New OleDbCommand(strSQL, objConnection)
                myDa.SelectCommand = objCommand
                Dim dt As New DataTable
                myDa.Fill(dt)
                Me.dgFiles.DataSource = dt
                Me.dgFiles.DataBind()
            Catch ex As Exception
                lblError.Text = "bindGrid(): " & ex.Message.ToString
            Finally
                GoToDBCloseConn()
            End Try
        End Sub

how cud this be done by altering the sql?

thanks for the response
itcnbwiseCommented:
OH, I get it now.  You don't want to limit it to DISTINCT results (as in, putting DISTINCT in front of APPLICATION) , you just want to not show the results for Application twice if it's repeated.

You can write a function to run on the datagrid page.

<%# disableDuplicates(DataBinder.Eval(Container.DataItem, "APPLICATION")) %>

Then in the function disableDuplicates:

Function disableDuplicates(thisAppValue)
      If thisAppValue = previousAppValue Then
         '### DUPLICATE, DON'T SHOW
         Return ""
      Else
         Return thisAppValue
      End If

      previousAppValue = thisAppValue
End Function

Make sure you declare:
Public previousAppValue As String

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
ASP.NET

From novice to tech pro — start learning today.