如何在ASP网上使用转发器数据绑定用于bootstrap carrousel幻灯片

时间:2015-10-30 12:00:16

标签: c# asp.net sharepoint-2013

从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>

从codebehind我得到列表,我在转发器上使用数据源和数据绑定方法:

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

在我的列表中有3个项目,在输出中,幻灯片显示每个幻灯片仅显示1个项目所有3个项目...在一些谷歌搜索之后我发现我必须在转发器内使用转发器项目数据包上面的代码我已经向你展示了(转发器内的转发器)...问题是我不知道如何使用转发器itemdatabound ...以及如何使列表中的3个项目出现在每个幻灯片上而不只显示1项!!! 任何帮助表示赞赏

PS:对不起,如果这是重新发布。

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

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

            }

上面的代码在page_load;

中 页面加载后

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

1 个答案:

答案 0 :(得分:0)

我曾经在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>

希望这能帮到你!