DataItem on Repeater.Items is always null

梦想的初衷 提交于 2019-12-04 10:39:30

For what purpose do you need the entire list? After the page is rendered, the list to which the Repeater is bound is not retained. If you need to keep it, you can put it into the session and retrieve it as necessary (on Page_Load, e.g.):

private List<MyProducts> _myList;
protected void Page_Load(object sender, EventArgs e)
{
    _myList = Session[MYPRODUCTSKEY] as IList;
}

You could also put this into your getter (check the session first, and invoke the webservice if necessary):

public List<MyProducts> TheProducts
{
 get 
 { 
     if(Session[MYPRODUCTSKEY] == null)
         Session[MYPRODUCTSKEY] = //invoke webservice
     return Session[MYPRODUCTSKEY] as List<MyProducts>;
 }
}

http://www.netnewsgroups.net/aspnet/t4049-question-repeater-dataitem.aspx

"DataItem is there only for the item-creation process, that is ItemCreated and ItemDataBound methods (ItemCreated when it happens due to call to DataBind)."

you can add ItemDataBound method and try to get DataItem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!