我尝试设置在转发器中绑定的img高度.但我不能:
HtmlImage proImg = item.FindControl("proImg") as HtmlImage;
proImg.Attributes.Add("style", "height:407px;");
谁能给我解决方案?
最佳答案 这可以使用ItemDataBound完成
public void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
// I'm assuming you are using HTML img tags
HtmlImage proImg = e.Item.FindControl("proImg") as HtmlImage;
proImg.Attributes.Add("style", "height:407px;");
}
}