两个Repeater嵌套使用

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

    例如:

aspx页面中:

  

                    

                        

                            

                                

                            

                            

                                

     

                                        

                                            

                                                

  •                                                 

                                                        

                                                            

                                                        

                                                    

                                                    

                                                        

                                                        立即进入

                                                    

                                                

  •  

                                            

                                        

     

     

                                    

                            

                        

                    

                

  很明显的是,此时在页面布局中是存在着两个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();

            }

        }

你可能感兴趣的:(C#开发,ASP,.NET,MVC&.NET)