repeater控件 php,Repeater控件绑定的三种方式

方式一

在aspx页面,写好需要循环输出的内容,一般包含用户自定义控件、服务器控件、Html格式的片段、和这种方式来动态显示获取到得数据列表:

">

                <%#%20(Container.DataItem%20as%20ProductImage).ResourceUrl%>

class="">

在cs文件,是用GetProductImageList方法来获取List类型的数据列表,并绑定在Repeater控件上面:

上面的不包含用户自定义控件、服务器控件,所以不需要ItemDataBound事件来对单个的数据项进行个性化的赋值

protected override void BindDataSource()

{

this.rpImage.DataSource = GetProductImageList();

this.rpImage.DataBind();

}

方式二

在aspx页面,这次包含了用户自定义控件,所以需要用到ItemDataBound事件来对列表中的每一个用户自定义控件进行个性化的赋值,用户自定义控件可以有公用的方法或者属性,

让我们在ItemDataBound事件中赋值:

在cs文件,用户自定义控件可以有公用的方法或者属性,让我们在ItemDataBound事件中赋值:

protected override void BindDataSource()

{

this.gvItemList.DataSource = productList;

this.gvItemList.DataBind();

}

protected override void OnInit(EventArgs e)

{

this.gvItemList.ItemDataBound += new RepeaterItemEventHandler(this.OnItemListDataBound);

base.OnInit(e);

}

private void OnItemListDataBound(object sender, RepeaterItemEventArgs e)

{

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;

}

}

}

}

方式三:

在aspx页面,可以显示设置OnItemDataBound属性,就不用像方式二那样,在cs文件中的OnInit方法中动态绑定,代码如下:

在cs文件:

protected override void BindDataSource()

{

base.BindDataSource();

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值