【发布时间】:2018-11-14 06:25:06
【问题描述】:
我有一个关于 C# 中继器的问题。我有默认宽度设置,它会根据 Page_Load 中的某些条件而改变,我希望将更改传递给 OnItemDataBound 上的图像。但是,似乎 OnItemDataBound 在 Page_Load 之前触发了,因为我在 Page_Load 中将宽度更改为 700,但是当加载图像时,它总是显示 380。如果 OnItemDataBound 不是要使用的正确函数,我应该调用哪个函数以便在调用 Page_Load(设置自定义宽度的位置)后更改图像宽度?我尝试了 OnPreLoad、OnLoad,但都没有奏效。
protected int width = 380;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
width = 700;
}
}
protected void Test_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
RepeaterItem item = e.Item;
if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
{
Image Image = (Image)e.Item.FindControl("Image");
Image.ImageUrl = Utilities.generateImage();
Image.Width = width;
}
}
【问题讨论】:
标签: c# asp.net repeater asprepeater