Fail To Cast: DirectCast(dataRow(CInt(enum AlertDataGridColumns.Details)),String)

P

pbd22

HI.
I am trying to acheive a custom spacer in datagrid as such:
<tr>
<td colspan="5" class="divider">&nbsp;</td>
</tr>

The code i am attempting to create this spacer is below:
I get a null refernce exception in the indicated line below.
Any ideas?

Sub dgSpacer_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
Dim item As DataGridItem = e.Item
' if its not an item or alternating item, get out of here
If item.ItemType <> ListItemType.Item And item.ItemType <>
ListItemType.AlternatingItem Then
Return
End If

' we need to access the datarow to get the text, so lets
get it
Dim dataRow As System.Data.DataRow =
DirectCast(item.DataItem, Data.DataRowView).Row
'now we need to create the new row, add the cell and put
in some text.

Dim oNewItem As New DataGridItem(item.ItemIndex,
item.DataSetIndex, item.ItemType)

Dim oNewCell As New TableCell()
oNewItem.Cells.Add(oNewCell)
oNewCell.ColumnSpan = item.Cells.Count
Dim oFullText As New Label()

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
THIS LINE
BREAKS''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
oFullText.Text = DirectCast(dataRow(CInt(enum
AlertDataGridColumns.Details)), String)


oNewCell.Controls.Add(oFullText)

' now w need to add it to the table (is always first item
in
'datagrid controls) and we're done!

MyDataGrid.Controls(0).Controls.Add(oNewItem)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top