Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 70
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chú ý Trong ASP NET 3.5., LayoutTemplate được yêu cầu và nó cần thiết để có một điều khiển serverside với một ID của itemContainer. Trong ASP NET 4., LayoutTemplate không còn cần thiết. | 664 CHAPTER 14 Using the ListView and DataPager Controls NOTE In ASPNET 3.5 the LayoutTemplate was required and it needed to contain a serverside control with an ID of itemContainer. In ASPNET 4 LayoutTemplate is no longer required. FIGURE 14.1 Displaying database records with a ListView control. The ItemTemplate renders each of the items from the data source or every other item when an AlternatingItemTemplate is present . In Listing 14.1 the ItemTemplate renders a div tag with a solid border. A data-binding expression is used with the div tag to display the value of the database Title column. The AlternatingItemTemplate is optional. If it is present every other item displayed by the ListView control is rendered with the AlternatingItemTemplate. In Listing 14.1 the AlternatingItemTemplate is used to give alternating items a silver background color. Finally the EmptyDataTemplate displays content when no results are retrieved from the data source. In Listing 14.1 the EmptyDataTemplate is used to display the text No Records Found when no items are returned from the data source. You can use the ListView control to render any HTML elements you can imagine. You can use the ListView control to render bulleted lists an HTML table a blog tag cloud or even the elements of a JavaScript array. For example the page in Listing 14.2 uses a ListView control to render an HTML table. LISTING 14.2 TableListView.aspx @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML 1.0 Transitional EN http www.w3.org TR xhtml1 DTD xhtml1-transitional.dtd html xmlns http www.w3.org 1999 xhtml head id Head1 runat server From the Library of Wow eBook Using the ListView Control 665 title Table ListView title head body form id form1 runat server div asp ListView ID lstMovies DataSourceId srcMovies runat server LayoutTemplate table thead tr th Title th th Director th tr thead tbody asp Placeholder id itemPlaceholder runat server tbody table LayoutTemplate ItemTemplate tr td Eval Title td td Eval .