A brief talk on DataPager in VS--practical skills

Source: Internet
Author: User

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" >
&LT;TR runat= "Server" >
<th runat= "Server" >ID</th>
<th runat= "Server" >store name</th>
</tr>
<tr id= "Itemplaceholder" runat= "Server" >
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
&LT;TR runat= "Server" >
&LT;TD class= "Item" >
<asp:label id= "Idlabel" runat= "server" text= ' <% #Eval ("CustomerID")%> '/>
</td>
&LT;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>

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.