dynamicContentListView_ItemDataBound

Posted by Community Admin on 04-Aug-2018 14:06

dynamicContentListView_ItemDataBound

All Replies

Posted by Community Admin on 06-Mar-2014 00:00

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>

Posted by Community Admin on 06-Mar-2014 00:00

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

Posted by Community Admin on 06-Mar-2014 00:00

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

Posted by Community Admin on 06-Mar-2014 00:00

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?

This thread is closed