Working with the System.Web.UI.WebControls.ListView in Sitecore

The new System.Web.UI.WebControls.ListView control is one of the new templated controls thats available in the Windows Presentation Foundation. But the control is not available for users in Sitecore. First you must add the control to the web.config in the typesThatShouldNotBeExpanded section (yes, that’s really it’s name):

<rendering>
  <typesThatShouldNotBeExpanded>
    <type>System.Web.UI.WebControls.Repeater</type>
    <type>System.Web.UI.WebControls.DataList</type>
    <type>System.Web.UI.WebControls.ListView</type>
  </typesThatShouldNotBeExpanded>
</rendering>

Now you can use the ListView control. The control is really cool since it allows you to do stuff without much code. This is an example of presenting the XML from a Google Search Appliance result. I won’t give you the codebehind, but I can tell you that all you have to do is that on Page_Load i feed the XML from the GSA request directly to the XmlDataSource. And that’s it:

<asp:XmlDataSource ID="xmlDataSource" EnableCaching="false" EnableViewState="false" runat="server" XPath="GSP/RES/R" >
</asp:XmlDataSource>

<asp:ListView DataSourceID="xmlDataSource" EnableViewState="false" id="SearchResultListView" runat="server">
  <LayoutTemplate>
      <ul>
        <asp:PlaceHolder runat="server" id="itemPlaceHolder" />
      </ul>
  </LayoutTemplate>
  <ItemTemplate>
    <li>
      <div>
        <a href="<%# XPath("U") %>">
          <%# XPath("T") %>
        </a>
      </div>
      <div>
        <%# XPath("S") %>
      </div>
      <div>
        <a href="<%# XPath("U") %>">
          <%# XPath("U") %>
        </a>
      </div>
    </li>
  </ItemTemplate>
  <EmptyDataTemplate>
    <ul>
      <li>
        <div>
          ... no match found ...
        </div>
      </li>
    </ul>
  </EmptyDataTemplate>
</asp:ListView>

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in .net, c#, Sitecore 6 and tagged , , , , , . Bookmark the permalink.

One Response to Working with the System.Web.UI.WebControls.ListView in Sitecore

  1. sluersen says:

    Hi Brian,

    Great article! Thanks for writing this. I just wanted to comment that working with ListView is a covered in Sitecore CMS 6.2 training for developers.

    For those who are interested in learning how to develop with Sitecore CMS 6.1 and greater, please see http://www.sitecore.net/en/Training/Course-Overview/CMS-62-Website-NET-Developer.aspx

    -seth
    sl_at-sitecore(net)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s