ArticleDirectory
Listview
Listview is a flexible data binding control that presents its own content according to the defined template.Unlike the Repeater control, listview adds advanced features (such as selection and editing ),They work in the same way as gridview.It creates a fast and concise grid with the least mark.
Listview enables a more flexible gridview that requires more work, or a simplified version of repeater that provides more details (controls contained in ASP. NET 1.x ).
Listview includes more templates:
Itemtemplate |
Content of all data items or odd rows |
Alternatingitemtemplate |
Content of even rows |
Itemseparatortemplate |
Separated content drawn in the middle of the project |
Seleteditemtemplate |
Content of the selected project |
Edititemtemplate |
Controls used by the project in editing mode |
Insertitemtemplate |
Insert controls used by the new project |
Layouttemplate |
Mark the packaged project list |
Grouptemplate |
If the group function is used, set the tag of the project group to be packaged. |
Groupseparatortemplate |
Separated content between groups |
Emptyitemtemplate |
If a group is used, it is used to fill in the empty projects in the last group, for example, 13 projects, 5 projects in each group, and 2 projects in the last group |
Emptydatatemplate |
Tag used to set the bound data object to null (no record or object is included) |
The most common reason for using listview is to create an uncommon layout! For example, create a table that displays multiple projects in the same row, or completely remove the table-based rendering. When constructing a page that displays a large amount of data, you often consider using the gridview first, while using the listview in more special scenarios.
To display data in the listview, follow the same process of consisting of the templatefield column in The gridview (at least use the itemtemplate template ):
<Asp: listview id ="Listemployees"Performanceid ="Sourceemployees"Runat ="Server">
<Itemtemplate>
<Span> <B>
<% # Eval ("Employeeid") %>-
<% # Eval ("Titleofcourtesy") %> <% # Eval ("Firstname") %> <% # Eval ("Lastname") %>
</B> <HR/>
<Small> <I>
<% # Eval ("Address") %> <Br/>
<% # Eval ("City") %>, <% # Eval ("Country") %>, <% # Eval ("Postalcode") %> <Br/>
<% # Eval ("Homephone") %>
</I> <br/>
<% # Eval ("Notes") %>
<Br/>
</Small> </span>
</Itemtemplate>
</ASP: listview>
To present itself, listview iterates the bound data and presents an itemtemplate for each project. Then, it puts all its content in the normal <span>.
Generally, you want to provide a layouttemplate to control the organization of items. If layouttemplate is included, the project is placed in layouttemplate. The following example shows the same behavior as the listview without layouttemplate:
<Asp: listview id ="Listemployees"Performanceid ="Sourceemployees"Runat ="Server">
<Layouttemplate>
<Asp: placeholder id ="Itemplaceholder"Runat ="Server"> </ASP: placeholder>
</Layouttemplate>
<Itemtemplate>
...
</Itemtemplate>
</ASP: listview>
When creating a layouttemplate for listview, you must specify the location where the itemtemplate content should be inserted. This can be achieved by adding a placeholder. This element will repeat each bound data item once. As long as the element ID is set to itemplaceholder, this element can be used as a placeholder.
The layouttemplate makes listview so flexible! Other data controls Use templates for data content, while listview uses templates for the overall structure of data.
Group
To use a group, you must first set the groupitemcount attribute, which determines the number of data items in each group:
<Asp: listview id = "listemployees" groupitemcount = "3"...>
After setting the group size, you must modify the layouttemplate. This is because the overall layout does not contain data items. It only contains groups and groups contain data items. To reflect this fact, you need to change the id from itemplaceholder to groupplaceholder:
<Layouttemplate>
<Table Border= "1">
<Tr ID= "Groupplaceholder" Runat= "Server">
</Layouttemplate>
Then you need to provide grouptemplate to encapsulate each group. Grouptemplate must provide a project placeholder:
<Grouptemplate>
<Tr> <TD Runat= "Server" ID= "Itemplaceholder" Valign= "TOP" />
</Grouptemplate>