Microsoft's DataPager paging function is very powerful, do not set the database stored procedures, just add a DataPager control, associated with the control to pagination, simple settings can have a good paging effect. Of course, to have a more ideal effect or to the front desk and background treatment.
DataPager display mode under WinForm:
The style under WebForm is controlled by Templatepagerfield,nextpreviouspagerfield and Numericpagerfield
The effect of WinForm can also be achieved by setting the coordination of several controls above, the most important of which is the Templatepagerfield control.
Here's a quick look at how the Templatepagerfield control can be set:
Copy Code code as follows:
<%@ Page language= "VB"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<script runat= "Server" >
Protected Sub Templatepagerfield_onpagercommand (ByVal sender as Object, _
ByVal e as Datapagercommandeventargs)
' Check which button raised the event
Select Case E.commandname
Case "Next"
Dim newindex as Integer = E.item.pager.startrowindex + e.item.pager.pagesize
If newindex <= E.totalrowcount Then
E.newstartrowindex = NewIndex
E.newmaximumrows = E.item.pager.maximumrows
End If
Case "Previous"
E.newstartrowindex = E.item.pager.startrowindex-e.item.pager.pagesize
E.newmaximumrows = E.item.pager.maximumrows
Case "a"
E.newstartrowindex = 0
E.newmaximumrows = E.item.pager.maximumrows
End Select
End Sub
</script>
<title>templatepagerfield.onpagercommand example</title>
<style type= "Text/css" >
Body
{
Text-align:center;
font:12px Arial, Helvetica, Sans-serif;
}
. Item
{
Border:solid 1px #2F4F4F;
Background: #E6E6FA;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<asp:listview id= "Storeslistview"
Datasourceid= "Storesdatasource"
runat= "Server" >
<LayoutTemplate>
<table width= "runat=" id= "Tblstore" >
<TR runat= "Server" >
<th runat= "Server" >ID</th>
<th runat= "Server" >store name</th>
</tr>
<tr id= "Itemplaceholder" runat= "Server" >
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<TR runat= "Server" >
<TD class= "Item" >
<asp:label id= "Idlabel" runat= "server" text= ' <% #Eval ("CustomerID")%> '/>
</td>
<TD align= "left" class= "Item" >
<asp:label id= "Namelabel" runat= "server" text= ' <% #Eval ("Name")%> '/>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<br/>
<asp:datapager runat= "Server"
Id= "Contactsdatapager"
Pagesize= "30"
Pagedcontrolid= "Storeslistview" >
<Fields>
<asp:templatepagerfield onpagercommand= "Templatepagerfield_onpagercommand" >
<PagerTemplate>
<asp:linkbutton id= "Firstbutton" runat= "Server" Commandname= "a"
text= "<<" enabled= ' <%# container.startrowindex > 0%> '/>
<asp:linkbutton id= "Previousbutton" runat= "Server" Commandname= "Previous"
Text= ' <%# (container.startrowindex-container.pagesize + 1) & "-" & (Container.startrowindex)%> '
visible= ' <%# container.startrowindex > 0%> '/>
<asp:label id= "Currentpagelabel" runat= "Server"
Text= ' <%# (Container.startrowindex + 1) & "-" & (IIf (Container.startrowindex + container.pagesize > Contain Er. Totalrowcount, Container.totalrowcount, Container.startrowindex + container.pagesize))%> '/>
<asp:linkbutton id= "Nextbutton" runat= "Server" Commandname= "Next"
Text= ' <%# (container.startrowindex + container.pagesize + 1) & "-" & (IIf Container.startrowindex + Container . Pagesize*2 > Container.totalrowcount, container.totalrowcount, Container.startrowindex + Container.PageSize*2)% > '
Visible= ' <%# (Container.startrowindex + container.pagesize) < Container.totalrowcount%> '/>
</PagerTemplate>
</asp:TemplatePagerField>
</Fields>
</asp:DataPager>
<asp:sqldatasource id= "Storesdatasource" runat= "Server"
connectionstring= "<%$ connectionstrings:adventureworks_dataconnectionstring%>"
Selectcommand= "SELECT [CustomerID], [name] from Sales.Store order BY [name]" >
</asp:SqlDataSource>
</form>
</body>