In a nutshell, the ListView control provides a very flexible means for displaying a collection of data while still offerring rich data features like paging, sorting, editing, inserting, and deleting.
Usage example: let's add a ListView control to the left column in the Lessons section that renders an unordered list with a list item for each node defined in the site map [1].
Notes:
The<asp:ListView ID="LessonsList" runat="server" DataSourceID="LessonsDataSource"><LayoutTemplate><ul><asp:PlaceHolder runat="server" ID="itemPlaceholder" /></ul></LayoutTemplate><ItemTemplate><li><asp:HyperLink runat="server" ID="lnkLesson"NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>' /></li></ItemTemplate></asp:ListView>
LayoutTemplate generates the markup for an unordered list (<ul>...</ul>) while the ItemTemplate renders each item returned by the SiteMapDataSource as a list item (<li>) that contains a link to the particular lesson [1].Note: To output a particular field value in the ItemTemplate, use the databinding syntax,
<%# Eval("columnName") %> [2]. We can also explicitly add a bullet item for Home in the
LayoutTemplate [1]: <LayoutTemplate><ul><li><asp:HyperLink runat="server" ID="lnkLesson"NavigateUrl="~/Default.aspx" Text="Home" /></li><asp:PlaceHolder runat="server" ID="itemPlaceholder" /></ul></LayoutTemplate>
Another usage example [3]:
<asp:ListView ID="ListView1" runat="server" DataSourceID="LessonsDataSource"> <LayoutTemplate> <asp:PlaceHolder runat="server" ID="itemPlaceholder" /> </LayoutTemplate> <ItemTemplate> <asp:HyperLink runat="server" ID="lnkLesson"NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>' /> </ItemTemplate> <ItemSeparatorTemplate> | </ItemSeparatorTemplate> </asp:ListView>
Related articles:
[1] - Specifying the Title, Meta Tags, and Other HTML Headers in the Master Page
[2] - Using ASP.NET 3.5's ListView
[3] - Specifying the Master Page Programmatically (see Step3)
No comments:
Post a Comment