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

Conditional Formatting with Date

3 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 04 Feb 2009, 07:54 PM
I am trying to do conditional formatting with a date field and having issues. I can get it to work by using a text field.

Protected

Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs)

 

 

If (TypeOf e.Item Is Telerik.WebControls.GridDataItem) Then

 

 

Dim dataitem As Telerik.WebControls.GridDataItem = e.Item

 

 

If (dataitem("Name").Text) = "Test" Then

 

dataitem(

"Name").ForeColor = System.Drawing.Color.Red

 

 

End If

 

 

End If

 

 

End Sub

 



I would like to capture a date field from the grid and check to see if it is over 10 days from the current date. I then want to change the color of the field to Red. I would like to make the entire row be red, but not sure what to use (ItemCreated, ItemInserted...)

3 Answers, 1 is accepted

Sort by
0
Joey
Top achievements
Rank 1
answered on 04 Feb 2009, 09:14 PM
I got it to work.

 

If (TypeOf e.Item Is Telerik.WebControls.GridDataItem) Then  

 

Dim dataitem As Telerik.WebControls.GridDataItem = e.Item

 

If (Convert.ToDateTime(dataitem("opent").Text) <= DateTime.Now.AddDays(-7)) Then

 

dataitem(

"opent").ForeColor = System.Drawing.Color.Red

 

 

End If

 

End If

Still trying to figure out how to make the whole row turn red not just that cell.

 

 

0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Feb 2009, 05:38 AM
Hi Joey,

Try the below line of code for applying style, for the entire row.

CS:
dataitem.ForeColor = System.Drawing.Color.Red 

Thanks,
Shinu.
0
Joey
Top achievements
Rank 1
answered on 06 Feb 2009, 10:07 PM
Shinu,

Thanks. Worked great!
Tags
Grid
Asked by
Joey
Top achievements
Rank 1
Answers by
Joey
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or