要在GridView中加入//實現分頁server
AllowPaging="true" PageSize="10"索引
// 分頁時觸發的事件
protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwDesignationName.PageIndex=e.newIndex;
bingDesignatioonName();
}事件
這裏我給出一個通用顯示分頁的模板(網上搜的,本身給出註釋)io
對應該事件中代碼爲ast
<PagerTemplate>模板
當Ì¡À前¡ã第̨²:object
<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>分頁
頁°3/共2:註釋
<asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>vi
頁°3
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首º¡Á頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上¦?一°?頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下?一°?頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾2頁°3</asp:LinkButton>
轉Áa到Ì?第̨²
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />頁°3
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
CommandName="Page" Text="GO" />
</PagerTemplate>
protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 獲得該控件
GridView theGrid = sender as GridView;
int newPageIndex = 0;
if (e.NewPageIndex==-3)
{
//點擊了Go按鈕
TextBox txtNewPageIndex = null;
//GridView較DataGrid提供了更多的API,獲取分頁塊可使用BottomPagerRow 或者TopPagerRow,固然還增長了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//獲得text控件
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}
if ( txtNewPageIndex!= null)
{
//獲得索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
//點擊了其餘的按鈕
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
//獲得新的值
theGrid.PageIndex = newPageIndex;
//從新綁定
bingDesignatioonName();
}
要在GridView中加入//實現分頁
AllowPaging="true" PageSize="10"
// 分頁時觸發的事件
protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwDesignationName.PageIndex=e.newIndex;
bingDesignatioonName();
}
這裏我給出一個通用顯示分頁的模板(網上搜的,本身給出註釋)
對應該事件中代碼爲
<PagerTemplate>
當Ì¡À前¡ã第̨²:
<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
頁°3/共2:
<asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
頁°3
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首º¡Á頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上¦?一°?頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下?一°?頁°3</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾2頁°3</asp:LinkButton>
轉Áa到Ì?第̨²
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />頁°3
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
CommandName="Page" Text="GO" />
</PagerTemplate>
protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e) { // 獲得該控件 GridView theGrid = sender as GridView; int newPageIndex = 0; if (e.NewPageIndex==-3) { //點擊了Go按鈕 TextBox txtNewPageIndex = null; //GridView較DataGrid提供了更多的API,獲取分頁塊可使用BottomPagerRow 或者TopPagerRow,固然還增長了HeaderRow和FooterRow GridViewRow pagerRow = theGrid.BottomPagerRow; if (pagerRow != null) { //獲得text控件 txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; } if ( txtNewPageIndex!= null) { //獲得索引 newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; } } else { //點擊了其餘的按鈕 newPageIndex = e.NewPageIndex; } //防止新索引溢出 newPageIndex = newPageIndex < 0 ? 0 : newPageIndex; newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex; //獲得新的值 theGrid.PageIndex = newPageIndex; //從新綁定 bingDesignatioonName(); }