Sitecore 5.3: Dynamically add headers to SheerUI listviews

Creating shell applications in Sitecore’s SheerUI is rather complex. But once you get the hang of it (= have modified enough existing sample code to get a working application) you can do amazing stuff.
Yesterday I had to dynamically alter the columns of my SheerUI listview, and here is what I did.

In the XML file I created my listview:

<Listview ID="IndexList" MultiSelect="false" View="Details" Width="100%" Background="white">
	<listviewheader id="IndexHeader">

The header is defined but empty, as I will create them myself.

In the .CS file I added both the InexList and the IndexHeader as private variables:

private Listview IndexList = null;
private ListviewHeader IndexHeader = null;

Then in the code where I fill the listview I started with creating my header sections by calling this function:

private void CreateHeader(string name)
  ListviewHeaderItem headerItem = new ListviewHeaderItem();
  Context.ClientPage.AddControl(IndexHeader, headerItem);
  headerItem.ID = Control.GetUniqueID("HI");
  headerItem.Value = name;
  headerItem.Name = name;
  headerItem.Header = name;

The function will create a new header item, add it to the header and set the header properties to the value contained in the “name” parameter.
When filling in values in the IndexList I have to refer to the header by the header property:

ListviewItem listItem = new ListviewItem();
Context.ClientPage.AddControl(IndexList, listItem);
listItem.ID = Control.GetUniqueID("I");
listItem.ColumnValues["somecolumnname"] = somevalue;

About briancaos

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

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.