Articles in this section
Category / Section

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

1 min read

 

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:

C#

protected void GridGroupingControl1_QueryCellStyleInfo(object sender,

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

{

   if ((e.TableCellIdentity.TableCellType ==

GridTableCellType.RecordFieldCell ||

   e.TableCellIdentity.TableCellType ==

GridTableCellType.AlternateRecordFieldCell))

    {

          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;

}

        }

     }

VB

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied