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

两个Repeater嵌套使用「建议收藏」在C#中有时存在着两个嵌套循环的存在,此时可以使用两个Repeater进行循环获取到。    例如:aspx页面中:                                                                                                          ‘alt=””>           

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

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();

            }

        }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号