Hi Anthony,
"Object reference not set to an instance of an object." means that
some reference of your program did not refer to an initialized object.
You can set a breakpoint in your application before the exception, then
check which reference does not refer properly.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Anthony Williams" <>
| Subject: Problems with UserControls within a DataGrid
| Date: Thu, 18 Sep 2003 14:25:52 +0100
| Lines: 47
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| NNTP-Posting-Host: host81-137-71-124.in-addr.btopenworld.com 81.137.71.124
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridc ontrol:6665
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
|
| 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("StockListIte m"),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
|
|
|