ListView with DataPager Server Control
ListViewANDDataPager.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>How to use ListView and DataPager</title>
<style type="text/css">
.TableCSS
{
border-style:none;
background-color:SaddleBrown;
width: 600px;
}
.TableHeader
{
background-color:DarkRed;
color:Snow;
font-size:large;
font-family:Verdana;
height:45px;
text-align:center;
}
.TableData
{
background-color:RosyBrown;
color:Snow;
font-family:Courier New;
font-size:medium;
font-weight:bold;
height:30px;
}
.TablePager
{
background-color:BurlyWood;
height:50px;
}
.PagerButtonCSS
{
color:Olive;
height:35px;
font-weight:bold;
font-family:Comic Sans MS;
}
.NumericButtonCSS
{
font-size:x-large;
font-family:Courier New;
color:SaddleBrown;
font-family:Comic Sans MS;
font-weight:bold;
}
.CurrentPageLabelCSS
{
font-size:xx-large;
font-family:Courier New;
color:Green;
font-weight:bold;
}
.NextPreviousButtonCSS
{
font-size:large;
font-family:Courier New;
color:Green;
font-weight:bold;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DeepPink; font-style:italic;">ListView AND DataPager Example: How To Use</h2>
<hr width="575" align="left" color="Orange" />
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="Select ProductID, ProductName From products Order By ProductID"
>
</asp:SqlDataSource>
<br />
<asp:ListView
ID="ListView1"
runat="server"
DataSourceID="SqlDataSource1"
>
<LayoutTemplate>
<table id="Table1" runat="server" class="TableCSS">
<tr id="Tr1" runat="server" class="TableHeader">
<td id="Td1" runat="server">Product ID</td>
<td id="Td2" runat="server">Product Name</td>
</tr>
<tr id="ItemPlaceholder" runat="server">
</tr>
<tr id="Tr2" runat="server" class="TablePager">
<td id="Td3" runat="server" colspan="2">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowFirstPageButton="true"
ShowPreviousPageButton="false"
ShowNextPageButton="true"
ButtonCssClass="PagerButtonCSS"
/>
<asp:NumericPagerField
NumericButtonCssClass="NumericButtonCSS"
NextPreviousButtonCssClass="NextPreviousButtonCSS"
CurrentPageLabelCssClass="CurrentPageLabelCSS"
/>
<asp:NextPreviousPagerField
ButtonType="Button"
ShowNextPageButton="false"
ShowLastPageButton="true"
ButtonCssClass="PagerButtonCSS"
/>
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="TableData">
<td>
<asp:Label
ID="Label1"
runat="server"
Text='<%# Eval("ProductID")%>'
>
</asp:Label>
</td>
<td>
<asp:Label
ID="Label2"
runat="server"
Text='<%# Eval("ProductName")%>'
>
</asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>

