前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >两个Repeater嵌套使用「建议收藏」

两个Repeater嵌套使用「建议收藏」

作者头像
全栈程序员站长
发布2022-09-14 16:48:02
3930
发布2022-09-14 16:48:02
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

在C#中有时存在着两个嵌套循环的存在,此时可以使用两个Repeater进行循环获取到。

例如:

aspx页面中:

<asp:Repeater ID=”IndexServiceImgs” runat=”server” OnItemDataBound=”RptAllOnItemDataBound22″>

<ItemTemplate>

<div class=”product”>

<a class=”bg_img” href=”#”>

<img src='<%#Eval(“cSerImg”) %>’ alt=””></a>

<div class=”look”>

<a href=”#”>

<div class=”lf”>

<img src=”images/look.png” alt=””>

</div>

<div class=”rf”>

<p>面部护肤热销排行榜</p>

<p><span>点击查看</span>>></p>

</div>

</a>

</div>

<div class=”show”>

<ul>

<asp:Repeater ID=”IndexGoodsImgs” runat=”server” OnItemDataBound=”RptAllOnItemDataBound11″>

<ItemTemplate>

<li>

<div class=”lf”>

<a href=”#”>

<asp:Image ID=”goodsImg” runat=”server” />

</a>

</div>

<div class=”rf”>

<a href=”#”><asp:Label ID=”goodsName” runat=”server”></asp:Label></a>

<a href=”#” class=”into”>立即进入</a>

</div>

</li>

</ItemTemplate>

</asp:Repeater>

</ul>

</div>

</div>

</ItemTemplate>

</asp:Repeater>

很明显的是,此时在页面布局中是存在着两个Repeater存在的。

aspx.cs页面中:

#region 初始化页面

public void initData()

{

string userPhone = “”;

try

{

//string phone = Session[“userPhone”].ToString();

//if (phone!=null && phone.Length==0)

//{

// Helper.Result(this,”!!!!!“);

// return;

//}

//else

//{

//userPhone = phone;

//根据用户手机号获取用户待付订单(这里的手机号是写死的 ,注意要改)

//Index页面中最上面滚动图片从数据库中获取

DataSet daifukuanSet = FuWuOtoWeiHelper.GetSysIndexBigTupians();

if (daifukuanSet.Tables[0].Rows.Count > 0)

{

this.IndexBigTupianRepeater.DataSource = daifukuanSet;

this.IndexBigTupianRepeater.DataBind();

}

//获取服务中的大图片

DataSet IndexServiceSet = FuWuOtoWeiHelper.GetSysIndexServicesTupians();

if (IndexServiceSet.Tables[0].Rows.Count > 0)

{

this.IndexServiceImgs.DataSource = IndexServiceSet;

this.IndexServiceImgs.DataBind();

}

//}

}

catch (Exception e)

{

throw e;

}

}

#endregion

//该方法是服务图片

protected void RptAllOnItemDataBound22(object sender, RepeaterItemEventArgs e)

{

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))

{

//string classname = ((Button)e.Item.FindControl(“gDel”)).Text;

DataRowView drv = (DataRowView)e.Item.DataItem;

Repeater rptProductList = (Repeater)e.Item.FindControl(“IndexGoodsImgs”);

//获取具体商品中的图片

DataSet IndexGoodsSet = FuWuOtoWeiHelper.GetSysIndexGoodsTupians();

if (IndexGoodsSet.Tables[0].Rows.Count > 0)

{

rptProductList.DataSource = IndexGoodsSet;

rptProductList.DataBind();

}

}

}

//该方法是商品展示信息

protected void RptAllOnItemDataBound11(object sender, RepeaterItemEventArgs e)

{

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))

{

//string classname = ((Button)e.Item.FindControl(“gDel”)).Text;

DataRowView drv = (DataRowView)e.Item.DataItem;

Image image = (Image)e.Item.FindControl(“goodsImg”);

image.ImageUrl = drv[“cContentImg”].ToString();

Label label = (Label)e.Item.FindControl(“goodsName”);

label.Text = drv[“cContentName”].ToString();

}

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/159101.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年7月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档