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

[Solved] Best practice for changing text color based on data in radgrid?

2 Answers 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 22 Apr 2013, 01:25 PM
I am converting an app to RadGrid controls, and I would like advice on the best way to convert some code that I had running in a DataGrid's RowDataBound event:
Private Sub gvAvailableTasks_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvAvailableTasks.RowDataBound
 
        If Not gvAvailableTasks.SelectedRow Is Nothing Then
            If gvAvailableTasks.SelectedRow.ID = e.Row.ID Then
                Exit Sub
            End If
        End If
 
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim dd As DateTime
            dd = CType(e.Row.Cells(6).Text, DateTime)
 
            If dd < Date.Now Then
                e.Row.Cells(6).BackColor = Drawing.Color.Red
            Else
 
                If DateDiff(DateInterval.Hour, Date.Now, dd) < 5 Then
                    e.Row.Cells(6).BackColor = Drawing.Color.Orange
                ElseIf DateDiff(DateInterval.Hour, Date.Now, dd) < 9 Then
                    e.Row.Cells(6).BackColor = Drawing.Color.Yellow
                End If
            End If
 
            ' Alert message
 
            Dim s As String = e.Row.Cells(5).Text
 
            If s.Trim <> " " And s.Trim <> "" Then
                e.Row.Cells(5).BackColor = Drawing.Color.Yellow
            End If
 
        End If
    End Sub

Basically the code changes the color of the due date to let the user know what is late. The last bit changes the background color if an alert message exists.

Thanks for your help!

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 22 Apr 2013, 02:04 PM
Protected Sub gvAvailableTasks_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvAvailableTasks.ItemDataBound

for starters


0
David
Top achievements
Rank 1
answered on 22 Apr 2013, 02:04 PM
After posting, I found this thread which answered my question:

http://www.telerik.com/community/forums/aspnet-ajax/grid/change-radgrid-cell-color-based-on-flag.aspx

I tested and it works perfect.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or