只能在Repeater的ItemDataBound事件中,用FindControl方法获取,然后重新绑定,在其它地方用FindControl方法不行的。比如在事件中可以这样写
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button btn = (Button)e.Item.FindControl("btnDetail");
int i = Convert.ToInt32(btn.CommandArgument.ToString());
List<Model.NewsBodyInfo> listBody = new List<NewsBodyInfo>();
listBody = bllNews.historyMessagesByNewsID(i);
Repeater rep = (Repeater)e.Item.FindControl("Repeaters");
rep.DataSource = listBody;
rep.DataBind();
}
温馨提示:答案为网友推荐,仅供参考