如何使用ASP网上的中继器数据绑定进行引导旋转幻灯片

本文关键字:幻灯片 旋转 数据绑定 中继器 ASP 何使用 | 更新日期: 2023-09-27 18:19:58

我从sharepoint 2013获取项目,并通过中继器调用它们。

<asp:Repeater ID="repeater_slideshow" runat="server">
     <ItemTemplate>
           <div class="<%# Container.ItemIndex == 0 ? "item active" : "item" %> row hidden-xs col-sm-12 slideshowItem">
                 <div class="wrapGallery col-sm-4">
                       <img class="img-responsive slideimage" src="<%# DataBinder.Eval(Container.DataItem, "Image") %>">
                       <div class="imgGalleryDescription">
                           <%# DataBinder.Eval(Container.DataItem, "HTMLField") %>
                       </div>
                 </div>
           </div>
     </ItemTemplate>
</asp:Repeater>

从codeehind中,我只得到了列表,并在中继器上使用了数据源和数据绑定方法:

Collection<HighLights> l = ContentHelper.ExecuteQuery<HighLights>(Portal.Lists.Highlight, ServerRelativeURL);                
this.repeater_slideshow.DataSource = l;
this.repeater_slideshow.DataBind();

在我的列表中有3个项目,在输出中,幻灯片在所有3个项目中,每个幻灯片只显示1个项目。。。经过一些谷歌搜索,我发现我必须使用中继器项目数据绑定在中继器内部,从上面的代码,我已经向你展示了(中继器内部的中继器)。。。问题是我不知道如何使用中继器项数据绑定。。。以及如何使列表中的3个项目显示在每张幻灯片上,而不是只显示1个项目!!!感谢提供的任何帮助

附言:很抱歉,如果这是转发。

编辑:找到解决方案:-)

<asp:Repeater ID="repeater"runat="server"OnItemDataBound="repeater_ItemDataBound">
                    <ItemTemplate>
                        <div class="<%# Container.ItemIndex == 0 ? "item active" : "item" %> row col-sm-12 slideshowItem">
                            <asp:Repeater ID="repeater_slideshow" runat="server">
                                <ItemTemplate>
                                    <div class="col-sm-4">
                                        <div class="wrapGallery">
                                            <img class="img-responsive slideimage" src="<%# DataBinder.Eval(Container.DataItem, "Image") %>">
                                            <div class="imgGalleryDescription">
                                                <%# DataBinder.Eval(Container.DataItem, "HTMLField") %>
                                            </div>
                                        </div>
                                    </div>
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>

码尾:

if(!this.IsPostBack){

            Collection<HighLights> d = ContentHelper.ExecuteQuery<HighLights>(Portal.Lists.Highlight, ServerRelativeURL);
              if (d != null && d.Count > 0)
            {
                this.Visible = true;
                int num1 = d.Count;
                int num2 = 3;
                decimal result = Convert.ToDecimal(num1) / Convert.ToDecimal(num2);
                int quociente = (int)Math.Ceiling(result);
                List<int> list = new List<int>(); ;
                for (int i = 1; i <= quociente; i++)
                {
                    list.Add(i);
                }
                this.repeater.DataSource = list;
                this.repeater.DataBind();
            }

上面的代码在pageload中;

页面加载后:

  protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Collection<HighLights> l = ContentHelper.ExecuteQuery<HighLights>(Portal.Lists.Highlight, ServerRelativeURL);
            Repeater rpt = e.Item.FindControl("repeater_slideshow") as Repeater;
            int aux = (int)e.Item.DataItem * 3;
            if (aux <= 3)
            {
                rpt.DataSource = l.Take(3);
            }
            else
            {
                rpt.DataSource = l.Skip(aux - 3).Take(3);
            }
            rpt.DataBind();
        }
    }

如何使用ASP网上的中继器数据绑定进行引导旋转幻灯片

我曾经在SharePoint 2010中做过同样的事情,我实际上使用了bxslider,它是滑块,可以让你定义每个幻灯片的元素数量(所以在中继器中不需要中继器)。

这是我的中继器代码:

<div id="slider" class="slider1">
       <asp:Repeater ID="repeater_slideshow" runat="server">
              <ItemTemplate>
                    <div class="slide">
                           // 1 item here
                   </div>
             </ItemTemplate>
        </asp:Repeater>
 </div>

希望这对你有帮助!