Search code examples
c#asp.net.netstatic-class

Trying to filter data in grid, receiving "Cannot create an instance of the static class" error


I am attempting to filter the items populated in a grid in the code behind. When I try to call my adapter from the data access layer, I am receiving the following error:

Cannot create an instance of the static class 'SFTIP.DataAccessLayer.InventoryAdapter'

The filter is meant to only display items in the grid related to the user role (AssetOwnershipProgramIds).

The error is in this segment new InventoryAdapter() of this line:

filteredList = new InventoryAdapter().GetAllByFilter(inventoryFilter);

Here is the code for the filter I am trying to build:

public List<Inventory> BindGrid()
{
    List<Inventory> filteredList = new List<Inventory>();
    SearchFilterInventory inventoryFilter = new SearchFilterInventory();
    User currentUser;

    currentUser = (Session["CurrentUser"] == null) ? (User)Session["CurrentUser"] : new User();
    if (currentUser.AdminPrograms.Count > 0)
    {
        inventoryFilter.AssetOwnershipProgramIds.Add(currentUser.AdminPrograms[0].ReferenceId);
        filteredList = new InventoryAdapter().GetAllByFilter(inventoryFilter);
    }

    return filteredList;
}

Can anyone provide some guidance on to where I am going wrong? I know that this is something fairly simple - this is an inherited project and I'm still trying to connect all the dots. Thank you for taking a look.


Solution

  • Sorry about the delay in coming back back to this - been out ill & other newer work priorities.

    So, - something so very simple. Made the mistake of assuming that "no one would ever do (or NOT do) that" and as programmers we ought to know better than to make that assumption, right? Anyhow, I had to add the <SelectParameters> back into ObjectDataSource in the aspx page:

        <asp:ObjectDataSource ID="odsItInventory" runat="server" SelectMethod="BindGrid" 
    TypeName="ADRUO.GUI.UserControls.ExtendedInventoryGridUserControl">
        <SelectParameters>
        <asp:SessionParameter Name="User" Type="Object" SessionField="CurrentUser" />
        </SelectParameters>
        </asp:ObjectDataSource>
    

    Thank you for the assistance - all of your comments were helpful, I believe each answer would have worked, had I had those parameters in the page. As it was, the param add was all that was required to resolve.