P
pbd22
HI.
I am trying to acheive a custom spacer in datagrid as such:
<tr>
<td colspan="5" class="divider"> </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
I am trying to acheive a custom spacer in datagrid as such:
<tr>
<td colspan="5" class="divider"> </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