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

Conditional row color from code behind

1 Answer 172 Views
Grid
This is a migrated thread and some comments may be shown as answers.
scott
Top achievements
Rank 1
scott asked on 11 Jun 2009, 04:01 PM
I am trying to change the rows back and foreground color based on data gleaned from cells. I have tried the below code but the cell data being returned is " " not the Boolean i was expecting from the sql data bound cells.

what am i doing wrong?

Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound 
        Try 
            If (TypeOf (e.Item) Is GridDataItem) Then 
                'Get the instance of the right type 
                Dim dataBoundItem As GridDataItem = e.Item 
 
                Debug.WriteLine(dataBoundItem("pause").Text) 
                Dim rclr As Drawing.Color 
                Dim tclr As Drawing.Color 
                If dataBoundItem("pause").Text = True Then 
                    rclr = Drawing.Color.DarkOrange 
                    tclr = Drawing.Color.Black 
                    GoTo RowSet 
                End If 
                If dataBoundItem("ready").Text = True And dataBoundItem("run").Text = True And dataBoundItem("done").Text = True Then 
                    'done 
                    rclr = Drawing.Color.Black 
                    tclr = Drawing.Color.Gray 
                ElseIf dataBoundItem("ready").Text = True And dataBoundItem("run").Text = True And dataBoundItem("done").Text = False Then 
                    'running  
                    rclr = Drawing.Color.DarkSalmon 
                    tclr = Drawing.Color.Black 
 
                ElseIf dataBoundItem("ready").Text = True And dataBoundItem("run").Text = False And dataBoundItem("done").Text = False Then 
                    'ready 
                    rclr = Drawing.Color.DarkOliveGreen 
                    tclr = Drawing.Color.Black 
                Else 
                    'not set, dont change a thing, well maybe do it incase 
                    rclr = Drawing.Color.Black 
                    tclr = Drawing.Color.White 
                End If 
RowSet: 
                Dim Row As TableRow 
                Row = CType(e.Item, TableRow) 
                Row.BackColor = rclr 
                Row.ForeColor = tclr 
            End If 
 
        Catch ex As Exception 
 
        End Try 
    End Sub 
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 11 Jun 2009, 08:45 PM
Hello Scott,

Please try one of the following suggestions to access the boolean value:

1.
If TypeOf e.Item Is GridDataItem Then 
    Dim item As GridDataItem = TryCast(e.Item, GridDataItem)  
    Dim boolVal As String = DataBinder.Eval(item.DataItem, "myBoolValue").ToString()  
End If 

2.
If TypeOf e.Item Is GridDataItem Then 
    Dim item As GridDataItem = TryCast(e.Item, GridDataItem)  
    Dim values As New Hashtable()  
    item.ExtractValues(values)  
    Dim boolVal As String = values("myBoolValue").ToString()  
End If 

Hope this helps.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
scott
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or