ASP.net 3.5, published with Visual studio®2008, introduces a new data-bound control-listview. I know what you're thinking: Why is there another data-bound control in the asp.net? After all, we have more than 10 controls to choose from when displaying data collection, including a DataGrid that is gradually no longer in use, a new and improved GridView, a very reliable and simple Repeater, unique and flexible DataList, convenient FormView and its slightly redundant peer DetailsView. Of course, there are one-dimensional list controls BulletedList, ListBox, DropDownList, RadioButtonList, and CheckBoxList.
Theoretically, ListView can replace all other data-bound controls in asp.net. There is no doubt about this point. You can use the ListView control instead of each of the other controls in the list above. ListView can also make some data-binding tasks easier than working with the first few controls, including CSS styling, flexible paging, and perfect sorting, inserting, deleting, and updating features.
Let's introduce the typical usage patterns of ListView and then explain the functionality of the controls, demonstrating their flexibility and power. At the end of this column, you will have enough information to decide how many data-bound controls should be retained in your asp.net toolbox.
ListView Foundation
ListView is a template-driven control, which means that it does not render any data by default--you must completely specify the HTML you want it to render in the form of a template. Like most template controls, ItemTemplate becomes the focus of your work, and you need to keep the HTML content of each row of the bound dataset in ItemTemplate.
The new feature in ListView, and the real difference between it and other controls, is the introduction of LayoutTemplate. In LayoutTemplate, you can define the top-level HTML you want to output as the content that the control renders. For example, if you want ListView to be rendered as a table, you can include the top <table> and <thead> elements in the LayoutTemplate, leaving the row and cell rendering ItemTemplate, as shown in Figure 1 (in this example , the bound data source displays a simple table that contains the movie title and release date. Figure 2 shows the browser rendering.
Figure 1 Using layouttemplate and ItemTemplate
<asp:listview runat= "Server" id= "_simpletablelistview"
datasourceid= "_moviesdatasource" >
< layouttemplate>
<table>
<thead>
<tr>
<th>ID</th>
& lt;th>title</th>
<th>release date</th>
</tr>
</thead>
&L t;tbody>
<asp:placeholder runat= "Server" id= "Itemplaceholder"/>
</tbody>
</tabl e>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><%# Eval ("Movie_ ID ")%></td>
<td><%# eval (" title ")%></td>
<td><%# eval (" Release_ Date ", {0:d}")%></td>
</tr>
</ItemTemplate>
</asp:ListView>
Figure 2 list displayed in the table