Tuesday, February 16, 2010

What is ListView?

ListView control offers a good deal of flexibility in styling a page. Using ListView, we get a lot more control over how our output looks. In effect, it is a styling control of sorts because we can use the full range of CSS that is now available in Visual Studio 2008.

To effectively use the ListView, we need to include a <LayoutTemplate> tag, and within the tag’s container, we add a PlaceHolder control with the ID named itemContainer:

<LayoutTemplate>
   <some style>
        <asp:PlaceHolder ID=”itemContainer” runat=”server”/>
</some style>
</LayoutTemplate>

All of the displayed data are styled by the style added in the <LayoutTemplate> and then placed in the PlaceHolder control.

Individual styling done in the <ItemTemplate> overrides the style from the <LayoutTemplate>, but with good planning and the full control that the ListView provides, the difference need not be at odds. In fact, the idea of the ListView is to give the designer both the flexibility and general layout features needed in design.

The sample application users one CSS style within the layout (generating a yellow background) and another CSS style for the names to be listed. The e-mail addresses that accompany the names use the default style, but are still cast on a yellow background.

No comments:

Post a Comment