DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Datagrid cell returning "" in ItemDataBound

  1. #1
    Join Date
    Jan 2006
    Posts
    33

    Datagrid cell returning "" in ItemDataBound

    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 are 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

  2. #2
    Join Date
    Jan 2006
    Posts
    33
    CType(e.Item.Cells(5).Controls(1), Label).Text solved my problem. Since I'm using a template column it is creating a Label (a.k.a. SPAN tags) in the table cell instead of just putting the text directly into the cell.

    Controls(0) didn't work for some reason because it returned "". Most likely the non-existent space between the TD and SPAN tags is the that literal control

Similar Threads

  1. Image in a Winforms Datagrid cell
    By livehed in forum .NET
    Replies: 0
    Last Post: 01-26-2006, 02:55 PM
  2. Datagrid Selected text within a cell
    By flipper22000 in forum .NET
    Replies: 2
    Last Post: 07-12-2005, 12:18 AM
  3. Replies: 0
    Last Post: 12-26-2002, 12:00 PM
  4. Replies: 0
    Last Post: 10-12-2002, 08:10 PM
  5. Replies: 5
    Last Post: 10-19-2001, 06:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center