方式一
在aspx页面,写好需要循环输出的内容,一般包含用户自定义控件、服务器控件、Html格式的片段、和<%# Eval("Name")%>这种方式来动态显示获取到得数据列表:
让我们在ItemDataBound事件中赋值:
ProductCellInfo productItem = (ProductCellInfo)e.Item.DataItem;
if (productItem != null)
{
ProductFullNameCell productName;
ImageCell image;
ProductControlCell productControlCell;
foreach (Control sub in e.Item.Controls)
{
productName = sub as ProductFullNameCell;
if (productName != null)
{
productName.InitProductFullName(productItem.Title, productItem.PromotionTitle, DispalyContentLength);
continue;
}
image = sub as ImageCell;
if (image != null)
{
image.InitImageCell2(productItem.ID, productItem.Code, productItem.Name, productItem.ImageUrl, productItem.ImageVersion);
continue;
}
productControlCell = sub as ProductControlCell;
if (productControlCell != null)
{
productControlCell.InitProductControlCell(productItem);
continue;
}
}
}
}
this.rptListCell.DataSource = this.List;
this.rptListCell.DataBind();
}
protected void RptAllOnItemDataBound(object sender, RepeaterItemEventArgs e)
{
CategoryInfo category = (CategoryInfo)e.Item.DataItem;
PlaceHolder pHot = e.Item.FindControl("pHot") as PlaceHolder;
PlaceHolder pNew = e.Item.FindControl("pNew") as PlaceHolder;
Literal lit = e.Item.FindControl("literalValidGiftOption") as Literal;
switch (category.PromotionStatus)
{
case "H":
pHot.Visible = true;
break;
case "N":
pNew.Visible = true;
break;
default:
break;
}
lit.Text = category.Name;
}
新闻热点
疑难解答