国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

VS中的DataPager分頁

2019-11-17 02:00:49
字體:
來源:轉載
供稿:網(wǎng)友

VS中的DataPager分頁

微軟的DataPager分頁功能很強大,不要設置數(shù)據(jù)庫存儲過程,只要添加個DataPager控件,關聯(lián)下要分頁的控件,簡單設置就可以有不錯的分頁效果。當然要有更理想的效果還是要前臺和后臺處理下。

winform下的DataPager 顯示模式:

webForm下的樣式由TemplatePagerField,NextPReviousPagerField和NumericPagerField控制

通過設置上面幾個控件的配合也可以達到winForm下的效果,這3個控件中最重要的是TemplatePagerField控件。

下面簡單看看TemplatePagerField控件可以怎么設置:

  1   <%@ Page language="VB" %>  2   3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  4     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  5   6 <script runat="server">  7   8   Protected Sub TemplatePagerField_OnPagerCommand(ByVal sender As Object, _  9     ByVal e As DataPagerCommandEventArgs) 10  11     ' Check which button raised the event 12     Select Case e.CommandName 13  14       Case "Next" 15         Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize 16         If newIndex <= e.TotalRowCount Then 17           e.NewStartRowIndex = newIndex 18           e.NewMaximumRows = e.Item.Pager.MaximumRows 19         End If 20  21       Case "Previous" 22         e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize 23         e.NewMaximumRows = e.Item.Pager.MaximumRows 24  25       Case "First" 26         e.NewStartRowIndex = 0 27         e.NewMaximumRows = e.Item.Pager.MaximumRows 28  29     End Select 30  31   End Sub 32  33 </script> 34  35 <html xmlns="http://www.w3.org/1999/xhtml" > 36   <head id="Head1" runat="server"> 37     <title>TemplatePagerField.OnPagerCommand Example</title>     38     <style type="text/CSS"> 39       body      40       { 41           text-align: center; 42           font: 12px Arial, Helvetica, sans-serif; 43       } 44       .item 45       { 46         border: solid 1px #2F4F4F; 47         background: #E6E6FA; 48       } 49     </style> 50   </head> 51   <body> 52     <form id="form1" runat="server"> 53  54       <h3>TemplatePagerField.OnPagerCommand Example</h3> 55  56       <asp:ListView ID="StoresListView"  57         DataSourceID="StoresDataSource" 58         runat="server"> 59         <LayoutTemplate> 60           <table width="350" runat="server" id="tblStore"> 61             <tr runat="server"> 62               <th runat="server">ID</th> 63               <th runat="server">Store Name</th> 64             </tr> 65             <tr id="itemPlaceholder" runat="server"> 66             </tr> 67           </table> 68          </LayoutTemplate> 69          <ItemTemplate> 70           <tr runat="server"> 71             <td class="item"> 72               <asp:Label ID="IDLabel" runat="server" Text='<%#Eval("CustomerID") %>' /> 73             </td>             74             <td align="left" class="item"> 75               <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("Name")%>' /> 76             </td> 77           </tr> 78         </ItemTemplate> 79       </asp:ListView> 80       <br /> 81  82       <asp:DataPager runat="server"  83         ID="ContactsDataPager"  84         PageSize="30" 85         PagedControlID="StoresListView"> 86         <Fields> 87           <asp:TemplatePagerField OnPagerCommand="TemplatePagerField_OnPagerCommand"> 88             <PagerTemplate>  89               <asp:LinkButton ID="FirstButton" runat="server" CommandName="First"  90                 Text="<<" Enabled='<%# Container.StartRowIndex > 0 %>' /> 91               <asp:LinkButton ID="PreviousButton" runat="server" CommandName="Previous"  92                 Text='<%# (Container.StartRowIndex - Container.PageSize + 1) & " - " & (Container.StartRowIndex) %>' 93                 Visible='<%# Container.StartRowIndex > 0 %>' /> 94               <asp:Label ID="CurrentPageLabel" runat="server" 95                 Text='<%# (Container.StartRowIndex + 1) & "-" & (IIf(Container.StartRowIndex + Container.PageSize > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize)) %>' /> 96               <asp:LinkButton ID="NextButton" runat="server" CommandName="Next" 97                 Text='<%# (Container.StartRowIndex + Container.PageSize + 1) & " - " & (IIf(Container.StartRowIndex + Container.PageSize*2 > Container.TotalRowCount, Container.TotalRowCount, Container.StartRowIndex + Container.PageSize*2)) %>'  98                 Visible='<%# (Container.StartRowIndex + Container.PageSize) < Container.TotalRowCount %>' /> 99             </PagerTemplate>100           </asp:TemplatePagerField>101         </Fields>102       </asp:DataPager>     103 104       <asp:SqlDataSource ID="StoresDataSource" runat="server" 105             ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"106             SelectCommand="SELECT [CustomerID], [Name] FROM Sales.Store ORDER BY [Name]">107       </asp:SqlDataSource>108 109     </form>110   </body>111 </html>

參考:https://msdn.microsoft.com/zh-SG/library/system.web.ui.webcontrols.templatepagerfield.pagercommand.aspx

https://msdn.microsoft.com/zh-cn/library/system.windows.controls.datapager(v=VS.95).aspx


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 许昌县| 张家口市| 呼和浩特市| 遵义县| 册亨县| 博白县| 安康市| 饶河县| 邛崃市| 金乡县| 中宁县| 右玉县| 义乌市| 汕头市| 美姑县| 崇州市| 大洼县| 乳源| 海原县| 塘沽区| 永顺县| 新巴尔虎右旗| 建始县| 迁西县| 阿鲁科尔沁旗| 隆德县| 苍山县| 台山市| 隆昌县| 聂拉木县| 霍山县| 淮阳县| 嘉祥县| 张北县| 凤阳县| 南京市| 惠州市| 凤山县| 绿春县| 邵阳县| 澄江县|