GridView的PagerTemplate分页

ContractedBlock.gif ExpandedBlockStart.gif Code
<asp:GridView ID="gvProject" runat="server" BorderColor="Gray" Height="20px" Width="98%" AllowPaging="True" AutoGenerateColumns="False" EmptyDataText="没有符合查询条件的数据!" OnDataBound="gvProject_DataBound" OnPageIndexChanging="gvProject_PageIndexChanging" OnRowDataBound="gvProject_RowDataBound" OnRowDeleting="gvProject_RowDeleting">
                                    
<EditRowStyle BackColor="SeaGreen" />
                                    
<SelectedRowStyle BorderColor="SeaGreen" />
                                    
<HeaderStyle BackColor="#718BD6" Font-Size="Small" ForeColor="White" Height="20px" />
                                    
<PagerSettings Mode="NumericFirstLast" />
                                    
<RowStyle Height="16px" />
                                    
<AlternatingRowStyle BackColor="#EDF5FF" />
                                    
<Columns>
                                        
<asp:BoundField DataField="ProjectID" HeaderText="项目ID" Visible="False" />
                                        
<asp:BoundField DataField="ProjectName" HeaderText="项目名称" />
                                        
<asp:BoundField DataField="ProjectStatus" HeaderText="项目状态" />
                                        
<asp:BoundField DataField="ssjd" HeaderText="实施进度" >
                                            
<ItemStyle ForeColor="Red" HorizontalAlign="Center" />
                                        
</asp:BoundField>
                                        
<asp:BoundField DataField="ssBeginDate" HeaderText="实施开始时间" DataFormatString="{0:d}" HtmlEncode="False" />
                                        
<asp:BoundField DataField="ssEndDate" HeaderText="要求结束时间" DataFormatString="{0:d}" HtmlEncode="False" />
                                        
<asp:BoundField DataField="UserName" HeaderText="项目负责人" />
                                        
<asp:HyperLinkField DataNavigateUrlFields="ProjectID" DataNavigateUrlFormatString="ProjectInfo.aspx?ProjectID={0}"
                                            HeaderText
="查看" Text="详细信息" />
                                        
<asp:TemplateField HeaderText="操作">
                                            
<ItemTemplate>
                                                
&nbsp;<asp:ImageButton ID="lbtnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/drop.gif" />
                                            
</ItemTemplate>
                                        
</asp:TemplateField>
                                    
</Columns>
                                    
<EmptyDataRowStyle ForeColor="Red" />
                                    
                                    
<PagerTemplate>
                                    当前第:
<asp:Label  ID="LabelCurrentPage" runat="server"
 Text
="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
 页
/共:
<asp:Label ID="LabelPageCount" runat="server"
 Text
="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> 页
 
 
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
 Visible
='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton>

<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
 Visible
='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton>

<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
 Visible
='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton>

<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
 Visible
='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton>
  转到第
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /> 
                                    
</PagerTemplate>
                                    
                                
</asp:GridView>

 

ContractedBlock.gif设置后台分页事件PageIndexChanging:

ExpandedBlockStart.gif
protected void gvProject_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        
//gvProject.PageIndex = e.NewPageIndex;
        
//this.BindProjectList();
        GridView theGrid = sender as GridView; // refer to the GridView
        int newPageIndex = 0;
        
if (-2 == e.NewPageIndex)
        { 
// when click the "GO" Button
            TextBox txtNewPageIndex = null;
            
//GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
            GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
            
//updated at 2006年月日:15:33
            if (null != pagerRow)
            {
                txtNewPageIndex 
= pagerRow.FindControl("txtNewPageIndex"as TextBox;   // refer to the TextBox with the NewPageIndex value
            }
            
if (null != txtNewPageIndex)
            {
                newPageIndex 
= int.Parse(txtNewPageIndex.Text) - 1// get the NewPageIndex
            }
        }
        
else
        { 
// when click the first, last, previous and next Button
            newPageIndex = e.NewPageIndex;
        }
        
// check to prevent form the NewPageIndex out of the range
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex 
= newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        
// specify the NewPageIndex
        theGrid.PageIndex = newPageIndex;
        
// rebind the control
        
// in this case of retrieving the data using the xxxDataSoucr control,
        
// just do nothing, because the asp.net engine binds the data automatically
        this.BindProjectList();//数据绑定的方法
    }
 1 <asp:GridView ID="gvProject" runat="server" BorderColor="Gray" Height="20px" Width="98%" AllowPaging="True" AutoGenerateColumns="False" EmptyDataText="没有符合查询条件的数据!" OnDataBound="gvProject_DataBound" OnPageIndexChanging="gvProject_PageIndexChanging" OnRowDataBound="gvProject_RowDataBound" OnRowDeleting="gvProject_RowDeleting">
 2                                     <EditRowStyle BackColor="SeaGreen" />
 3                                     <SelectedRowStyle BorderColor="SeaGreen" />
 4                                     <HeaderStyle BackColor="#718BD6" Font-Size="Small" ForeColor="White" Height="20px" />
 5                                     <PagerSettings Mode="NumericFirstLast" />
 6                                     <RowStyle Height="16px" />
 7                                     <AlternatingRowStyle BackColor="#EDF5FF" />
 8                                     <Columns>
 9                                         <asp:BoundField DataField="ProjectID" HeaderText="项目ID" Visible="False" />
10                                         <asp:BoundField DataField="ProjectName" HeaderText="项目名称" />
11                                         <asp:BoundField DataField="ProjectStatus" HeaderText="项目状态" />
12                                         <asp:BoundField DataField="ssjd" HeaderText="实施进度" >
13                                             <ItemStyle ForeColor="Red" HorizontalAlign="Center" />
14                                         </asp:BoundField>
15                                         <asp:BoundField DataField="ssBeginDate" HeaderText="实施开始时间" DataFormatString="{0:d}" HtmlEncode="False" />
16                                         <asp:BoundField DataField="ssEndDate" HeaderText="要求结束时间" DataFormatString="{0:d}" HtmlEncode="False" />
17                                         <asp:BoundField DataField="UserName" HeaderText="项目负责人" />
18                                         <asp:HyperLinkField DataNavigateUrlFields="ProjectID" DataNavigateUrlFormatString="ProjectInfo.aspx?ProjectID={0}"
19                                             HeaderText="查看" Text="详细信息" />
20                                         <asp:TemplateField HeaderText="操作">
21                                             <ItemTemplate>
22                                                 &nbsp;<asp:ImageButton ID="lbtnDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/drop.gif" />
23                                             </ItemTemplate>
24                                         </asp:TemplateField>
25                                     </Columns>
26                                     <EmptyDataRowStyle ForeColor="Red" />
27                                     
28                                     <PagerTemplate>
29                                     当前第:
30 <asp:Label  ID="LabelCurrentPage" runat="server"
31  Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
32  页/共:
33 <asp:Label ID="LabelPageCount" runat="server"
34  Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> 页
35  
36  <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
37  Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton>
38 
39 <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
40  Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton>
41 
42 <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
43  Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton>
44 
45 <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
46  Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton>
47   转到第
48 <asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
49 <asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /> 
50                                     </PagerTemplate>
51                                     
52                                 </asp:GridView>

转载于:https://www.cnblogs.com/qxw0816/archive/2009/04/20/1439717.html

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值