Error: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

后端 未结 7 1160
后悔当初
后悔当初 2021-01-07 21:59

I am trying to set a property of my .ascx controls from an .aspx using that control.

So in one of my .aspx which has this control in it, I have the

7条回答
  •  北海茫月
    2021-01-07 22:30

    The Add method doesn't return a reference to the list. You have to do this in two steps:

    ItemListt.ItemList = new List();
    ItemListt.ItemList.Add(item);
    

    Alternatively use a local variable to hold the reference before you put it in the property:

    List list = new List();
    list.Add(item);
    ItemListt.ItemList = list;
    

提交回复
热议问题