0

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

Edited by krokodajl: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by nakor77
0

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.

Edited by nakor77: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.