<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>

 

设置后台分页事件PageIndexChanging:

 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();//数据绑定的方法
    }>

相关文章: