(828) 862-6667

Sitefinity Blogs


  • Little known Sitefinity configuration settings
  • More detailed examples for Sitefinity component usage
  • Work-arounds for Sitefinity limitations
  • Discoveries and Ah-Ha moments 

ListView: Limit the Items Displayed

by Rich Winslow | Oct 10, 2010

I was interested in displaying a list of testimonials on the bottom of a home page, but I didn't want all the testimonials, only a few with a link to see more.

I discovered that the ListView control doesn't have a property in the Basic or Advanced to allow this.

I found Ivan Dimitrov's forum entry  about blogs and modify it for my purpose.

Here are the specific steps to implement a ListView with a limited number of visible items:

  • Created a new directory in the root of my website: ~/CustomTemplates
  • Created a subdirectory for the ListView: ~/CustomTemplates/Lists
  • Copied the default list view control: ~/Sitefinity/ControlTemplates/Lists/ExpandedListView.ascx to ~/CustomTemplates/Lists/ShortExpandedList.ascx

     

  • Edited the custom user control
  • Added Javascript to the top of the custom control (see below) to hide all list items beyond the hardcoded 'pagesize' value.
  • Modified the 'pagesize' variable in the javascript to set the # of list items to display (ex. 3 most recent items displayed out of 50)
  • Made aesthetic changes to the control for a good visual separation of the items
  • Then in Sitefinity, I edited the page I wanted this custom ListView control on
  • Dropped a ListView control on page (Expand the 'Lists' group, drag and drop the ListView control into the page)
  • Clicked to Edit the ListView control
  • Selected Expanded List mode
  • Clicked on the Advanced tab and expanded the Appearance section
  • Pasted in the template path for this custom control: ~/CustomTemplates/Lists/ShortExpandedList.ascx
  • Saved the changes
  • Tested it out and tweaked the styles

Below is the custom control I created from the Sitefinity default ExpandedListView control.  Note: this is a Sitefinity v3.7 version of their control, you may have to modify it for future versions (or come back here for an update :) )

<!--Control Language="C#"-->
<telerik:CssFileLink id="CssFileLink1" runat="server" Media="screen" EmbeddedFileName="Telerik.Lists.Resources.ControlTemplates.Frontend.listsCommonLayout.css"></telerik:CssFileLink>
<script src="http://code.jquery.com/jquery-latest.min.js" originalAttribute="src" originalPath="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">

function pageLoad()
{
var itemsSize = ($('li.items').length);
var pagesize = 3;
var itemsToShow = itemsSize / pagesize;
if (itemsSize > itemsToShow)
{
hideItems(pagesize);
}
}

function hideItems(pagesize)
{

$('li.items').each(function() {
if (($(this).index() + 1) > pagesize) {
$(this).hide();
}
})

}

function showItems()
{
$('li.items').each(function()
{
$(this).show();
});

}

</script>

<asp:Repeater id="lists" runat="server">
<itemtemplate />


<h1 class="sf_listTitle"><asp:Literal id="listTitle" runat="server"></asp:Literal></h1>


<asp:Repeater id="listItems" runat="server">
<headertemplate />
<ul class="sf_expandedList" style="list-style-type: none;">

<itemtemplate />
<li class="items"><hr />

<h3 class="sf_listItemTitle"><asp:Literal id="headline" runat="server"></asp:Literal></h3>
<div class="sf_listItemBody"><asp:Literal id="content" runat="server"></asp:Literal></div>

</li>

<footertemplate />
</ul>

</asp:Repeater>

</asp:Repeater>


<hr />

Comment

  1.    
     
     
      
       

Why Give Our Secrets Away?

I often get asked why I'm willing to journal all of my Sitefinity discoveries. People think I'm insane to give away for free what I labored over at some point.

Let me answer that in 2 parts:

  • Why journal my discoveries?

    Because I forget and I want to a library of knowledge to refer back to. Oh but it is far worse than that... THREE TIMES now, I've gone to Google and searched for a solution to a problem, only to find MY OWN BLOG entry is #1 in Google and viola! there's the solution!
  • Why give it away for free?

    Because others have been kind enough to do it for us; what goes around, comes around.

    There are all levels of experience, thus someone with less experience may defer to us when needed.

    The lines of 'competition' are very much blurred; in our minds competition is a potential customer or partnership in the right situation.

    We maintain healthy partnerships with one of our competitors; they come to us when they need help and visa versa.

    There is plenty of work out there for everyone if you are putting out quality work and you are straightforward with clients and competition.

Talk to us about how we can help YOU!

 


Don't miss out!

Keep up with our Sitefinity discoveries!
Click on the RSS feed icon below or sign up for our newsletter.


Email Address:
     















Company Info  |   Contact Us  |   Site Map  |   Terms  |   Privacy Policy  |  

Automated Results Computer Consulting LLC, 222 South Caldwell Street, Brevard, NC 28712 (828) 862-6667