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

Forums / Developing with Sitefinity / OnItemDataBound in LibraryItemList

OnItemDataBound in LibraryItemList

4 posts, 1 answered
  1. Levi Burton
    Levi Burton avatar
    11 posts
    Registered:
    16 Apr 2010
    10 Aug 2010
    Link to this post
    I would like to customize the LibraryItemList control template a little bit and need to handle the imagesList OnItemDataBound event, but when I my event handler is called my repeater items are null.  

    My goal is to show or hide a control depending on the files extension.

    This is my code:

    <asp:Repeater runat="server" ID="imagesList" Visible="true"  OnItemDataBound="imagesList_OnItemDataBound">

    protected void imagesList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = (RepeaterItem)e.Item;
    }

    Is what I would like to do possible?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Aug 2010
    Link to this post
    Hi Levi Burton,

    1. You could try subscribing in Page_Load for ItemDataBound event of the Repeater with ID="imagesList"

    public void Page_Load(object sender, EventArgs e)
      {
          this.imagesList.ItemDataBound += new RepeaterItemEventHandler(imagesList_ItemDataBound);
      }
     
      void imagesList_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
          if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
          {
               
          }
      }

    Here you can cast e.Item.DataItem to IContent object in case you need to get a content item.

    2. Another option is creating a custom class that inherits from LibraryItemList, overriding SelectContent method and after calling the base you can subscribe for ItemDataBound event.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Levi Burton
    Levi Burton avatar
    11 posts
    Registered:
    16 Apr 2010
    10 Aug 2010
    Link to this post
    Thanks Ivan,

    I was actually wrong, all my DataItems were not null, only the first item in the ItemDataBound event!  I had just assumed they were all null.  Once I added a check for the null DataItem everything is ok.  Sorry for wasting your time on this one, and thanks for the quick response!
  4. Levi Burton
    Levi Burton avatar
    11 posts
    Registered:
    16 Apr 2010
    10 Aug 2010
    Link to this post
    Oh, and I did not know you could cast e.Item.DataItem to IContent, thats good to know!  It was actually my next question.  Thanks again!
Register for webinar
4 posts, 1 answered