M
MattB
I swear I've made this work no problem before and I'm not sure what's
gone wrong.
I have a form with a datagrid that I'm binding to a DatTable I generate
on the fly. If I just bind and load the page I can see all my data fine.
Now I want to add a textbox for each row and pre-populate that box with
values from my DataTable. So I created a OnItemDataBound event and it's
firing. My problem is that any time I try to reference data in the
source table I get a runtime error NullReferenceException.
Below is my ItemDataBound event. Can anyone see what my mistake(s)
is/are? It pukes when it hits that Case statement that refers to
e.Item.DataItem. I don't get it. Thanks!
Sub dgGuest_ItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)
Dim editCell As TableCell = e.Item.Controls(1), tb As New TextBox
'only bother with non-header or footer items
If (e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem) Then
End If
Select Case e.Item.DataItem("ColName")
Case "birth_date"
tb.Text = CType(e.Item.DataItem("val"),
Date).ToShortDateString
editCell.Controls.Add(tb)
Case Else
tb.Text = Convert.ToString(e.Item.DataItem("val"))
editCell.Controls.Add(tb)
End Select
End Sub
gone wrong.
I have a form with a datagrid that I'm binding to a DatTable I generate
on the fly. If I just bind and load the page I can see all my data fine.
Now I want to add a textbox for each row and pre-populate that box with
values from my DataTable. So I created a OnItemDataBound event and it's
firing. My problem is that any time I try to reference data in the
source table I get a runtime error NullReferenceException.
Below is my ItemDataBound event. Can anyone see what my mistake(s)
is/are? It pukes when it hits that Case statement that refers to
e.Item.DataItem. I don't get it. Thanks!
Sub dgGuest_ItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)
Dim editCell As TableCell = e.Item.Controls(1), tb As New TextBox
'only bother with non-header or footer items
If (e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem) Then
End If
Select Case e.Item.DataItem("ColName")
Case "birth_date"
tb.Text = CType(e.Item.DataItem("val"),
Date).ToShortDateString
editCell.Controls.Add(tb)
Case Else
tb.Text = Convert.ToString(e.Item.DataItem("val"))
editCell.Controls.Add(tb)
End Select
End Sub