|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
NullReferenceException with dynamic DataGridI have a page using a dynamically added DataGrid. DataGrid contains a
TemplateColumn and is bound to a DataTable in a protected method called from OnInit. ItemCommand and SortCommand events are wired and working. When I then moved the DataGrid into a Table, Row, Cell and Panel control to format the output I get a null reference exception suggesting I have declared a reference to the DataGrid. This is clearly not the case. When I catch the error the DataGrid is rendered properly. Can someone explain this phenomina? Everthing is the same apart from the DataGrid is now nested deeper in the Control hierarchy?? -- MG Sorry!, obviously I meant the NullReferenceException suggests I haven't
declared a reference to the DataGrid. -- Show quoteHide quoteMG "Mark Gilkes" wrote: > I have a page using a dynamically added DataGrid. DataGrid contains a > TemplateColumn and is bound to a DataTable in a protected method called from > OnInit. ItemCommand and SortCommand events are wired and working. When I then > moved the DataGrid into a Table, Row, Cell and Panel control to format the > output I get a null reference exception suggesting I have declared a > reference to the DataGrid. This is clearly not the case. When I catch the > error the DataGrid is rendered properly. Can someone explain this phenomina? > Everthing is the same apart from the DataGrid is now nested deeper in the > Control hierarchy?? > -- > MG What you should check is whether or not the DataItem is null prior to
accessing it. It will be null after a PostBack and also for Header, Footer and non-Item rows for the DataGrid. You can check the type of the row to ensure it will have a defined DataItem value. You can read about it here... http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagriditem.itemtype.aspx The rows which have the DataItem defined are the Item and AlternatingItem rows. Ultimately you can resolve your issue and see what is happening with the debugger. I wrote up some instructions to do that here... http://brennan.offwhite.net/blog/2006/09/12/debugging-aspnet-20-with-visual-studio-2005/ Brennan Stehling http://brennan.offwhite.net/blog/ Mark Gilkes wrote: Show quoteHide quote > Sorry!, obviously I meant the NullReferenceException suggests I haven't > declared a reference to the DataGrid. > -- > MG > > > "Mark Gilkes" wrote: > > > I have a page using a dynamically added DataGrid. DataGrid contains a > > TemplateColumn and is bound to a DataTable in a protected method called from > > OnInit. ItemCommand and SortCommand events are wired and working. When I then > > moved the DataGrid into a Table, Row, Cell and Panel control to format the > > output I get a null reference exception suggesting I have declared a > > reference to the DataGrid. This is clearly not the case. When I catch the > > error the DataGrid is rendered properly. Can someone explain this phenomina? > > Everthing is the same apart from the DataGrid is now nested deeper in the > > Control hierarchy?? > > -- > > MG
Uploading big files
GridView Nested - Is it Possible? Can't repopulate DropdownList control during postback? Query on user control Div background image from CSS Getting multi values from a list box How to use Socket Connection Custom Control at deisgn time Role of the web.config file with UserControls [2.0] Equivalant to the DateTimePicker |
|||||||||||||||||||||||