I have a problem where my cells in the datagrid are returning "" in the ItemDataBound event. When there is data in the cells, but in my code both e.Item.Cells(5).Text and CType(e.Item.Cells(5).Controls(0), LiteralControl).Text. Does anyone have any ideas? Here is my code below.
Code:
Private Sub dgLicenses_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgLicenses.ItemDataBound
Dim strExpiryDate As String
' Set any expired documents to red. Skip over the header and footer rows.
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
' Get the expiration date of the current row
If e.Item.ItemIndex <> dgLicenses.EditItemIndex Then
REM - why is these returning ""?
strExpiryDate = CType(e.Item.Cells(5).Controls(0), LiteralControl).Text
strExpiryDate = Trim(e.Item.Cells(5).Text)
Else
strExpiryDate = Trim(CType(e.Item.Cells(5).Controls(0), TextBox).Text)
End If
' Set the background color to red if the document is expired
If IsDate(strExpiryDate) Then
If CDate(strExpiryDate) > System.DateTime.Today Then
e.Item.BackColor = System.Drawing.Color.Red
End If
End If
End If
End Sub