How to use ListView control in

ListView Web Server Control
ListView is an ASP.NET web server control. ListView allow us to data bind with DataSource and display data. We can show ListView data items in pages. ListView can display data items individually or it can group data items.

.NET developers can format data using templates and styles in a ListView control. ListView is popular for display data in any repeating structure. It is a similar server control to the DataList and Repeater server control. But ListView has more facility such as user can edit, update, insert, delete, sort and even page data. All those are ListView built in feature, so you don't need to code for any one facility.

LisView can data bind with SqlDataSource control using it's DataSourceID property. By binding data with data source control we can get it's built in advantage such as paging data, sorting data, inserting, deleting and editing data.

ListView DataSource property allow us to data bind with many objects such as ADO.NET DataSet and DataReader. But if you use DataSource property, you need to write code for paging, sorting, editing etc functionality.

ListView allow .NET developers to display data as individual items or in groups. Developers can define data items by templates. ListView templates similar as DataList and Repeater control.

If you use ListView layout template then you need to create a LayoutTemplate. The LayoutTemplate must have control that act as a data place holder. PlaceHolder output each item as defined ItemTemplate. GroupTemplate allow .NET developers to group ListView data.

ListView control used templates are LayoutTemplate, ItemTemplate, ItemSeparatorTemplate, GroupTemplate, GroupSeparatorTemplate, EmptyItemTemplate, EmptyDataTemplate, SelectedItemTemplate, AlternatingItemTemplate, EditItemTemplate and InsertItemTemplate.

To enable ListView data paging we can use DataPager server control inside LayoutTemplate. EditItemTemplate allow us to edit ListView data and InsertItemTemplate allow to insert new data.

The following example source code will help you to better understand how ListView works in ASP.NET.

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html>

<script runat="server">
<html xmlns="" >
<head id="Head1" runat="server">
    <title>ListView control - how to use ListView control in</title>
    <style type="text/css">
            width: 600px;
            font-family:Courier New;
    <form id="form1" runat="server">
        <h2 style="color:Navy; font-style:italic;">ListView Control Example: How To Use ListView Control</h2>
        <hr width="550" align="left" color="PowderBlue" />
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select ProductID, ProductName From products Order By ProductID"
        <br />

                <table runat="server" class="TableCSS">
                    <tr runat="server" class="TableHeader">
                        <td runat="server">Product ID</td>
                        <td runat="server">Product Name</td>
                    <tr id="ItemPlaceholder" runat="server">
                    <tr runat="server">
                        <td runat="server" colspan="2">
                            <asp:DataPager ID="DataPager1" runat="server">
                                    <asp:NextPreviousPagerField ButtonType="Link" />
                                    <asp:NumericPagerField />
                                    <asp:NextPreviousPagerField ButtonType="Link" />
                <tr class="TableData">
                            Text='<%# Eval("ProductID")%>'
                            Text='<%# Eval("ProductName")%>'
More examples