ASP.NET 我在后台为Repeater绑定数据源,如何同时获得Repeater中的控件?
2个回答
展开全部
只能在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();
}
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询