Comparing column value with the same column in the above row

2 posts, 0 answers
  1. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 05 Jun 2009 Link to this post

    Hi guys,

    I want to compare a cell text / uniquefield.value to the same field above.
    If the text is the same as above (double post) I want to make the text red.

    I thought this shouldn't be so hard, but my approach isn't working.

    My first thought was to have a public string that I change in the databound event once I've compared it to the cell text:
            Dim nameCell As TableCell = dataItem("Name"
            If nameCell.Text = strLastPlayer Then 
                nameCell.ForeColor = Drawing.Color.Red 
            End If 
            strLastPlayer = nameCell.Text 

    This doesn't work, it always returns true and the text is always red.
    My second try was this:
            If e.Item.ItemIndex > 0 Then 
                Dim intPrev As Integer = e.Item.ItemIndex - 1 
                Dim prevItem As GridDataItem = RadGrid1.Items(intPrev) 
     
                Dim nameCell As TableCell = dataItem("Name"
                Dim prevNameCell As TableCell = prevItem("Name"
     
                If nameCell.Text = prevNameCell.Text Then 
                    nameCell.ForeColor = Drawing.Color.Red 
                End If 
     
                'strLastPlayer = nameCell.Text 
     
            End If 

    But it has the same result, always true and all fields red.
    I must be missing something obvious here, can anyone spot it?

    Regards,
    -DJ-
  2. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 09 Jun 2009 Link to this post


    I figured this out.
    The nameCell.Text was always returning an empty string, so I was always comparing an empty string to another empty string, thus getting true on all occasions.

    This was because:
    This approach of obtaining cell values works for auto-generated columns and built-in column types except for template columns. For template columns you must find the control in the grid cell and extract its value.

    as seen here: http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

    I was using a template column, although not with any controls inside. By adding a label and then extracting the value from it in the itemdatabound event I solved this problem.

    Regards,
    -DJ-

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top