Implementation Code of ListView template and binding in ASP. Net

Source: Internet
Author: User

Asp. net has a Table and a GridView space to display multiple pieces of data, and most of the data used to bind a dataset uses the GridView, but the template definition of the GridView is a little troublesome and I think it is not good in performance, although it is mainly the data source query method, this time I recorded not the query method, but used ListView for template definition and Data Source binding.

In the WPF behind Microsoft, ListView is a convenient control. I used many template definitions in the later WPF development, including ListBox, GridView, and ListView. In short, ListView has its own merits, however, ListView uses more. Because the ListView style is quite beautiful, I am a visual system and a little lazy, so I only use the default style to define the template, so I chose ListView for a lot of things, run the Code directly. In fact, there is nothing to say. If you do more, you will naturally understand the meaning.

The Code is as follows: Copy code


<Asp: ListView ID = "lv_ProjectItems" runat = "server">
<LayoutTemplate>
<Ul id = "biaoge" style = "list-style: none">
<Ol>
Currently, all unfinished projects </ol>
<Asp: PlaceHolder ID = "itemPlaceholder" runat = "server"/>
</Ul>
</LayoutTemplate>
<ItemTemplate>
<Ol onmouseover = "this. style. backgroundColor = '# ebeff9';" onmouseout = "this. style. backgroundColor =''; ">
<A href = "../Search/ProjectInfo. aspx? ProjectID = <% # Eval ("ID") %> & action = end "target =" _ blank ">
<Li> <span style = "display: block; width: 150px; float: left"> [<% # Eval ("ProjectID ") %>] </span> <% # Eval ("ProjectName") %> </li> </a>
</Ol>
</ItemTemplate>
</Asp: ListView>

The preceding <% # Eval ("ID") %> and <% # Eval ("ProjectID") %> and <% # Eval ("ProjectName ") %> indicates that the fields "ID", "ProjectID", and "ProjectName" are bound to the current position in the result set.

The Code is as follows: Copy code

Lv_ProjectItems.DataSource = items. OrderByDescending (t => t. ID );
Lv_ProjectItems.DataBind ();

Conclusion: The binding method is the same for other controls. If you are interested, you can try other controls.

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.