大家好,又见面了,我是你们的朋友全栈君。
在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