We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to compare two cell values of the same row and apply styles to the cells depending on the comparision?


To apply styles to the Grid cells we have to use QueryCellStyleInfo event.

Please refer the below code snippet which illustrates how to compare two cell values of the same row and apply styles to the cells depending on the comparision:


protected void GridGroupingControl1_QueryCellStyleInfo(object sender,

Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellStyleInfoEventArgs e)


   if ((e.TableCellIdentity.TableCellType ==

GridTableCellType.RecordFieldCell ||

   e.TableCellIdentity.TableCellType ==



          if (e.Style.TableCellIdentity.RowIndex ==5)


if (e.TableCellIdentity.Column.Name == "Numbers1")


  val1 = (System.Int32)e.Style.CellValue;


if (e.TableCellIdentity.Column.Name == "Numbers2")


    val2 = (System.Int32)e.Style.CellValue;


if ((val2 < val1) && (e.TableCellIdentity.Column.Name == "Numbers2") &&

(e.Style.CellValue.ToString() == val2.ToString()))

e.Style.BackColor = System.Drawing.Color.Blue;

else if ((e.TableCellIdentity.Column.Name == "Numbers1") &&

(e.Style.CellValue.ToString() == val1.ToString()))

e.Style.BackColor = System.Drawing.Color.Orange;





Public Sub GridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Web.UI.WebControls.Grid.Grouping.GridTableCellStyleInfoEventArgs)

If (e.TableCellIdentity.TableCellType = GridTableCellType.RecordFieldCell OrElse e.TableCellIdentity.TableCellType = GridTableCellType.AlternateRecordFieldCell) Then

If e.Style.TableCellIdentity.RowIndex = 5 Then

If e.TableCellIdentity.Column.Name = "Numbers1" Then

val1 = CInt(e.Style.CellValue)

End If

If e.TableCellIdentity.Column.Name = "Numbers2" Then

val2 = CInt(e.Style.CellValue)

End If

If (val2 < val1) AndAlso (e.TableCellIdentity.Column.Name = "Numbers2") AndAlso (e.Style.CellValue.ToString() = val2.ToString()) Then

e.Style.BackColor = System.Drawing.Color.Blue

ElseIf (e.TableCellIdentity.Column.Name = "Numbers1") AndAlso (e.Style.CellValue.ToString() = val1.ToString()) Then

e.Style.BackColor = System.Drawing.Color.Orange

End If

End If

End If

End Sub



Article ID: Published Date: Last Revised Date: Platform: Control:
756 04/30/2011 07/10/2014 ASP.NET Web Forms (Classic) GridGroupingControl
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon