A
Anthony Williams
Afternoon all,
I'm having a slight issue with a user control that I've written for an
application. The DataGrid I'm using has a single TemplateColumn inside which
I have placed my control with id="StockListItem". The datagrid binds without
problems, and the controls are all sitting there happily, waiting to be
modified by using the .ItemDataBound event.
I have a custom class behind the control called StockListItemControl, which
inherits System.Web.UI.UserControl, which allows me to have properties for
each of the custom controls which are in the datagrid, so that I can modify
these properties in the ItemDataBound event.
This is where I'm starting to have fun with null reference exceptions. I'm
trying DESPERATELY to get hold of the controls once they're inside the
datagrid. After a bit of looping around the .Controls collection, I've
managed to get hold of the container in which my StockListItemControl
resides:
' -- Handle the ItemDataBound event to modify control properties
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
' Find the control with ID="StockListItem"
Dim Ctrl As StockListItemControl =
CType(e.Item.Controls(0).FindControl("StockListItem"),StockListItemControl)
' And modify it's properties
Ctrl.Price = "Some price as a string"
Ctrl.Mileage = "Some mileage"
Ctrl.Make = "Some make"
End Sub
' -- End code -- '
I keep getting the error whenever I try and reference Ctrl: "Object
reference not set to an instance of an object."
Any ideas please?
Cheers,
Anth
I'm having a slight issue with a user control that I've written for an
application. The DataGrid I'm using has a single TemplateColumn inside which
I have placed my control with id="StockListItem". The datagrid binds without
problems, and the controls are all sitting there happily, waiting to be
modified by using the .ItemDataBound event.
I have a custom class behind the control called StockListItemControl, which
inherits System.Web.UI.UserControl, which allows me to have properties for
each of the custom controls which are in the datagrid, so that I can modify
these properties in the ItemDataBound event.
This is where I'm starting to have fun with null reference exceptions. I'm
trying DESPERATELY to get hold of the controls once they're inside the
datagrid. After a bit of looping around the .Controls collection, I've
managed to get hold of the container in which my StockListItemControl
resides:
' -- Handle the ItemDataBound event to modify control properties
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
' Find the control with ID="StockListItem"
Dim Ctrl As StockListItemControl =
CType(e.Item.Controls(0).FindControl("StockListItem"),StockListItemControl)
' And modify it's properties
Ctrl.Price = "Some price as a string"
Ctrl.Mileage = "Some mileage"
Ctrl.Make = "Some make"
End Sub
' -- End code -- '
I keep getting the error whenever I try and reference Ctrl: "Object
reference not set to an instance of an object."
Any ideas please?
Cheers,
Anth