I have a strange problem. I have ascx control and I have only ListView in it. When I use generic method to fill this ListView with data I get Exceptiion - ListView is null. But when I use method without generics(with known parameter) everything is working fine(ListView is not null). Could you explain me why something like this is happening?

this works fine:

public void SetListViewDataSource(List<BaseBO> data)
    {
        this.ListView.DataSource = data;
        this.ListView.DataBind();
    }

and this is not working:

public void SetListViewDataSource<T>(List<T> data) where T : BaseBO, new()
    {
        this.ListView.DataSource = data;
        this.ListView.DataBind();
    }

I am using Model-View-Presenter pattern

The only reason I can think of without knowing what your BaseBO class looks like is that you do not have a constructor for that class which takes no parameters. The new() constraint requires that whatever type T is it must have a parameterless constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.