Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6097959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:06:08+00:00 2026-05-23T13:06:08+00:00

As the title says, I have a method that throws a NullReferenceException in my

  • 0

As the title says, I have a method that throws a NullReferenceException in my DataGridView Binding method.

Here is my code (simplified):

private void GridViewBinding(string sortExpression, string direction)
        { 

             string lang = string.Empty;
             Regex appnoRegex = new Regex("\\d{4}(-)\\d{4}(-)\\d{1}");
             int colCount = gvData.Columns.Count;

            DataView dv = GetData();
            //DataView dvApplication = GetApplicationsData();

            //Sorting only on postback, else rel. docs won't appear
            if (Page.IsPostBack)
            {
                dv.Sort = sortExpression + " " + direction;
            }

            lblTotal.Text = dv.Count.ToString();

            gvData.DataSource = dv;
            gvData.DataKeyNames = new string[] { "InterventionID", "ItemNumber" };
            gvData.DataBind();

            ChangeHeaders(_docTypeQueryStr, colCount, appnoRegex);
}

The change header Method:

private void ChangeHeaders(string DocType, int colCount, Regex appnoRegex)
        {
            switch (DocType.ToUpper())
            {
                //intervention documents
                case "I":
                    lblDocumentTypeTitle.Text = Resources.GeneralResouces.lblTypeTitleInterventionsText;
                    lblIntervenorLastName.Text = Resources.GeneralResouces.lblIntervenorLastNameInterventionText;
                    break;
                //Replies document
                case "R":
                    lblDocumentTypeTitle.Text = Resources.GeneralResouces.lblTypeTitleRepliesText;
                    lblIntervenorLastName.Text = Resources.GeneralResouces.lblIntervenorLastNameRepliesText;
                    break;
                //Answer Documents
                case "AR":
                    lblDocumentTypeTitle.Text = Resources.GeneralResouces.lblTypeTitleAnswersText;
                    lblIntervenorLastName.Text = Resources.GeneralResouces.lblIntervenorLastNameAnswerText;
                    break;
                //if none of teh above
                default:
                    //Notice of consultations
                    if (applicationCount == 0 && !appnoRegex.IsMatch(_eventNoQueryStr))
                    {
                        lblIntervenorLastName.Text = Resources.GeneralResouces.lblIntervenorText;
                    }
                    //Part 1 applications
                    else
                    {
                        //Part 1 applications and notices with applications
                        if (applicationCount != 0 || appnoRegex.IsMatch(_eventNoQueryStr))
                        {
                            lblIntervenorLastName.Text = Resources.GeneralResouces.lblIntervenorWithApplicationsText;
                        }
                    }
                    break;
            }

This is the stack trace I get:

[NullReferenceException: Object reference not set to an instance of an object.]
   Interventions._Default.ChangeHeaders(String DocType, Int32 colCount, Regex appnoRegex) +13
   Interventions._Default.GridViewBinding(String sortExpression, String direction) +331
   Interventions._Default.Page_Load(Object sender, EventArgs e) +888
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

From what I understood of it, the error comes from theChangeHeaders method. I tried putting the ChangeHeaders method in comments and there were no more errors. That told me the error was really from the ChangeHeaders method. However, it is the first time that I get a NUllReferenceException from a Method and I am lost as to why it is doing that. Specially that the said method is in the code and there are no typo when I call it.

How can I fix this, thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:06:09+00:00Added an answer on May 23, 2026 at 1:06 pm

    Check the value of _docTypeQueryStr.

    Probably you are passing a null value to ChangeHeaders and doing a ToUpper().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty much what the title says really. We have some code that is .NET
Basically what the title says... I need to have an image that when clicked,
Basically, what the title says. I have several properties that combine together to really
OK, I don't think the title says it right... but here goes: I have
Basically, what the title says. I have several properties that combine together to really
Title says it mostly. I want to add a simple extension method to the
As title says, how do I call a java class method from a jsp,
Like the title says Where and How (i.e. if encrypted, with what method) does
As the title says, what is the method to access which item is displayed
It's basically what the title says.. I have a form with a select control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.