This is a migrated thread and some comments may be shown as answers.

Comparing column value with the same column in the above row

1 Answer 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
-DJ-
Top achievements
Rank 1
-DJ- asked on 05 Jun 2009, 03:45 PM
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-

1 Answer, 1 is accepted

Sort by
0
-DJ-
Top achievements
Rank 1
answered on 09 Jun 2009, 05:09 PM

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-

Tags
Grid
Asked by
-DJ-
Top achievements
Rank 1
Answers by
-DJ-
Top achievements
Rank 1
Share this question
or