(2) 总页数Text="">(3) 首页、上一页、下一页、尾页Visible="">首页Visible="">上一页Visible="">下一页Visible="">尾页' />注:将上述代码放在GridView的Page">

gridview自定义分页

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>">

(2) 总页数

Text="<%# ((GridView)Container.NamingContainer).PageCount %>">

(3) 首页、上一页、下一页、尾页

Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页

Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页

Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页

Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页

注:将上述代码放在GridView的

PageIndexChanging事件中加入如下代码

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) {

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 engine binds the data automatically }

相关文档
最新文档