Talking about pagination of DataPager in VS and talking about vsdatapager

Source: Internet
Author: User

Talking about pagination of DataPager in VS and talking about vsdatapager

The paging function of Microsoft DataPager is very powerful. Do not set database stored procedures. You only need to add a DataPager control and associate it with the control to be paged. A simple setting can have a good paging effect. Of course, the ideal results should be processed at the front-end and back-end.

DataPager display mode in winform:

Styles in webForm are controlled by TemplatePagerField, NextPreviousPagerField, and NumericPagerField.

By setting the cooperation of the preceding controls, you can also achieve the effect of winForm. The most important of the three controls is the TemplatePagerField control.

The following describes how to set the TemplatePagerField control:

Copy codeThe Code is 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 "First"
E. NewStartRowIndex = 0
E. NewMaximumRows = e. Item. Pager. MaximumRows
End Select
End Sub
</Script>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<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>
</Head>
<Body>
<Form id = "form1" runat = "server">
<H3> TemplatePagerField. OnPagerCommand Example <Asp: ListView ID = "StoresListView"
Performanceid = "StoresDataSource"
Runat = "server">
<LayoutTemplate>
<Table width = "350" runat = "server" 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 = "First"
Text = "<" Enabled = '<% # Container. StartRowIndex> 0%>'/>
<Asp: LinkButton ID = "previusbutton" 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> Container. 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>
</Html>

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.