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

Change cell background conditionally by row datakey

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 01 Oct 2015, 03:08 PM

I would like to change the cell color of a specific cell in a specific row defined by two datakey values. For example using the following Grid:

Type     ID    Adjustments
PG        1            $10.00
V3         1            $10.00
PG        2            $134.35
V3         2            $178.60

I would like to change the background of the cells in the Adjustments column for the cells with values $134.35 and $178.60 based on the Type = PG and ID = 2 and the Type = V3 and the ID = 2. Might even get away with simply the ID = 2.

 

I attempted:

 

Protected Sub rgd_Paycheck_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_Paycheck.ItemCreated
 
        For Each item As GridDataItem In rgd_Paycheck.MasterTableView.Items
            Dim keyrow_PGPayrollID As String = item.GetDataKeyValue("PGPayrollID").ToString()
            Dim keyrow_RECTYPE As String = item.GetDataKeyValue("RECTYPE").ToString()
 
            If keyrow_PGPayrollID = 2 And keyrow_RECTYPE Like "PG" Then
 
                Dim TotalAdjustments_PG As String = item("TotalAdjustments").Text
                Session("TotalAdjustments_PG") = TotalAdjustments_PG
            End If
 
            If keyrow_PGPayrollID = 2 And keyrow_RECTYPE Like "V3" Then
 
                Dim TotalAdjustments_V3 As String = item("TotalAdjustments").Text
                Session("TotalAdjustments_V3") = TotalAdjustments_V3
            End If
 
            If Session("TotalAdjustments_PG") <> Session("TotalAdjustments_V3") Then
                Label1.Text = "OOPS"
 
                If (TypeOf (e.Item) Is GridDataItem) Then
                    'Get the instance of the right type
                    Dim dataBoundItem As GridDataItem = e.Item
 
                    'Check the formatting condition
                    If keyrow_RECTYPE = "PG" Then
                        dataBoundItem("TotalAdjustments").ForeColor = Color.Red
                        dataBoundItem("TotalAdjustments").Font.Bold = True
                        'Customize more...
                    End If
                End If
 
            End If
 
        Next
 
    End Sub

 And attempted:

 

Protected Sub rgd_Paycheck_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles rgd_Paycheck.ItemDataBound
 
    If TypeOf e.Item Is GridDataItem Then
 
        Dim dataBoundItem As GridDataItem = DirectCast(e.Item, GridDataItem)
 
        If dataBoundItem.GetDataKeyValue("PGPayrollID").ToString() = "PG" And dataBoundItem.GetDataKeyValue("RECTYPE").ToString() = "V3" Then
            dataBoundItem("TotalAdjustments").ForeColor = Color.Red
            dataBoundItem("TotalAdjustments").Font.Bold = True
        End If
 
    End If
 
End Sub

As always, any assistance much appreciated.

Allan

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 06 Oct 2015, 11:23 AM
Hi Allan,

Could you verify that the PGPayrollID and RECTYPE fields are included in the DataKeyNames collection as explained in the following section:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Share this question
or