Very asp.net: The unique data-bound control you will need to use

Source: Internet
Author: User
Tags eval

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.