Problem Iterating Through A Datagrid

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: kscdavefl (kscdavefl_at_discussions.microsoft.com)
Date: 03/16/05


Date: Wed, 16 Mar 2005 06:27:02 -0800

I am using the following code to iterate through a DataGrid to change the
value in one of the columns:

private void UpdateFCA()
                {
                        for (int i = 0; i <= reportGrid.Items.Count; i++)
                        {
                                DataGridItem item = reportGrid.Items[i];
                                TextBox fcaText = (TextBox)item.FindControl("fca");
                                if (fcaText.Text == "")
                                {
                                        fcaText.Text = "N";
                                }
                                else
                                {
                                        fcaText.Text = "Y";
                                }
                        }
                }

When I run the code I get the following error:

Server Error in '/5YrPlan' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 143: DataGridItem item = reportGrid.Items[i];
Line 144: TextBox fcaText = (TextBox)item.FindControl("fca");
Line 145: if (fcaText.Text == "")
Line 146: {
Line 147: fcaText.Text = "N";
 

Source File: c:\inetpub\wwwroot\5yrplan\reportform.aspx.cs Line: 145

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
   _5YrPlan.reportForm.UpdateFCA() in
c:\inetpub\wwwroot\5yrplan\reportform.aspx.cs:145
   _5YrPlan.reportForm.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\5yrplan\reportform.aspx.cs:33
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750

 

Can anyone help with the code to make this error go away?

Thanks,

Dave



Relevant Pages

  • Problem saving database BLOB to file
    ... I am however using a datareaders instead of a dataset (it's the only real ... Object reference not set to an instance of an object. ... Please review the stack trace for more information ... Source Error: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Variable Scope
    ... Select Case FileType ... > Object reference not set to an instance of an object. ... Please review the stack trace for more information about the error and where it originated in the code. ... > Source Error: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: I am not sure how to interpret this...
    ... I believe your code did have some portion that is reading the XML file. ... Please review the stack trace for more information ... Exception Details: System.NullReferenceException: Object reference not set ... Source Error: ...
    (microsoft.public.dotnet.languages.csharp)
  • I am not sure how to interpret this...
    ... running a help page and got this error message. ... Please review the stack trace for more information ... Exception Details: System.NullReferenceException: Object reference not set ... Source Error: ...
    (microsoft.public.dotnet.languages.csharp)
  • Server Error
    ... I just wonder if anyone could help me with this error I'm receiving, ... when tha page was updated from another computer who is accesing the page too, ... Please review the stack trace for more information ... Source Error: ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)