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 8983151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:45:58+00:00 2026-06-15T20:45:58+00:00

I am trying to populate a gridview with a list of objects via linq

  • 0

I am trying to populate a gridview with a list of objects via linq (I only want to show certain objects with a specific property).

I get the error…

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source

Source Error:

Line 1364: returnInvoices = (List)Session[“Invoices”];
Line 1365:
Line 1366: var partInvoices = from i in returnInvoices
Line 1367: where i.PartNo == partNo
Line 1368: select new Source File:
c:\inetpub\wwwroot…\Form.aspx.cs Line: 1366

protected void DoInvoicePopUp(string partNo)
{
    List<Invoice> returnInvoices = (List<Invoice>)Session["Invoices"];

    var partInvoices = from i in returnInvoices
                       where i.PartNo == partNo
                       select new
                       {
                           i.InvoiceID,
                           i.InvoiceNo,
                           i.InvoiceLine,
                           i.InvoiceDate,
                           i.OrderNo,
                           i.OrderLine,
                           i.OrderRel,
                           i.OrderLineItem,
                           i.OrderLineQty,
                           i.CustomerPO,
                           i.Serialized
                       };

    GridView3.DataSource = partInvoices;
    GridView3.DataBind();

    pnlBlanket.Visible = pnlInvoiceSearch.Visible = true;
}

I’m not sure what I’m doing wrong. The List has 200+ objects in it, so how can it be null?

  • 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-06-15T20:46:00+00:00Added an answer on June 15, 2026 at 8:46 pm

    Looks like Session[“Invoices”] is null, if it should never be null you need to look at why this is hapening, if it is fine for it to be null just use the as keyword instead of casting e.g.

    List<Invoice> returnInvoices = Session["Invoices"] as List<Invoice>;
    

    Session[“Invoices”] might still be null but it won’t throw the null ref exception on the cast, it will just you will just see that returnInvoices is null, which you can then check for and handle.

    EDIT

    I willl leave the above as general advice but actually from the stack trace it looks like partNo is null.

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

Sidebar

Related Questions

I am trying to get a gridview to populate text from the database call
I trying to populate the dropdown list when page was loaded.But it is not
I am trying to populate a List<Image> by reading the name of the each
I am trying to populate a spinner, but am getting an error. Here is
I am trying to populate the list li from the LoginAction on to the
I am trying to populate a dropdown list when some other drop down gets
I am trying to populate a gridview using LayoutInflator.. According to me the code
iam trying to populate the HyperlinkButton.NavigateUri Property with a string from the properties... But
I'm trying to populate a listview from another class, but I'm geting this error:
I am new to jQuery, trying to populate a GridView or Telerik RadGrid using

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.