+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / dynamicContentListView_ItemDataBound

dynamicContentListView_ItemDataBound

4 posts, 0 answered
  1. David Rhodes
    David Rhodes avatar
    42 posts
    Registered:
    24 May 2005
    06 Mar 2014
    Link to this post

    Hi,

     I'm building a carousel using a custom module and ascx, in my code I need to build up some HTML to act as the pager for the carousel so i have this. 

    int pagerIndex = 0;    
     
    protected void dynamicContentListView_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
            {
                RadListViewDataItem item = (RadListViewDataItem)e.Item;
                DynamicContent dataItem = item.DataItem as DynamicContent;
     
                if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
                {
                    ........
     
                    // Build pager
                     
                        PagerLinks.Controls.Add(new LiteralControl(string.Format("<a data-slide-index=\"{0}\">{1}</a>", pagerIndex, dataItem.GetValue("Title").ToString())));
                        pagerIndex++;
                     
                }
            }

    For some reason though I am getting double the amount of links added to PagerLinks, I have 3 items but it outputs this, any idea why?

     

    <a data-slide-index="0">Peace of mind</a>
    <a data-slide-index="1">Advice</a>
    <a data-slide-index="2">Lorem ipsum</a>
    <a data-slide-index="3">Peace of mind</a>
    <a data-slide-index="4">Advice</a>
    <a data-slide-index="5">Lorem ipsum</a>

  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    06 Mar 2014 in reply to David Rhodes
    Link to this post

    Hi David,

     Are you using the API to get the Dynamic Content Items from the CMS? You probably have to filter that result to only get back the 'Live' items, as where it by default would return both the 'Live' and 'Master' items.

    Kind regards,
    Daniel

  3. David Rhodes
    David Rhodes avatar
    42 posts
    Registered:
    24 May 2005
    06 Mar 2014 in reply to Daniel Plomp
    Link to this post

    The way i'm doing it is

    • drag Carousel control on to page
    • in advanced properties, set the view to /.../CarouselList.ascx

    There are only 3 items in total, sitefinity seems to be calling the itemdatabound method twice for each item

    The actual RadListView displaying the items  shows 3 items correctly

  4. Stacey
    Stacey avatar
    291 posts
    Registered:
    18 Oct 2012
    06 Mar 2014 in reply to David Rhodes
    Link to this post

    Unless you really need to test for normal vs alternating try using this check and see if that helps.

     if (e.Item is RadListViewItem)

     

    Also, how are you setting up the event for ItemDataBound?

4 posts, 0 answered