ASP.NET 我在后台为Repeater绑定数据源,如何同时获得Repeater中的控件?

如题所述

只能在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();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-31
在ItemDataBound事件里用
(控件类型)e.Item.FindControl("控件ID")函数查找Repeater中的控件!
相似回答