GridView如何实现当前页码和总记录数

2022-03-20 国际 91阅读
参照如下代码改下html样式就好,不明白的留言我




'/>页
共/'/>页




'/>







protectedvoidgrdvSearchResult_PageIndexChanging(objectsender,GridViewPageEventArgse)
{
//this.grdvSearchResult.PageIndex=e.NewPageIndex;
////this.DataBind();

DataTableaaa=newDataTable();
aaa=(DataTable)ViewState["TableForAllSelect"];

grdvSearchResult.DataSource=aaa;
grdvSearchResult.DataBind();
grdvSearchResult.Visible=true;

GridViewtheGrid=senderasGridView;//refertotheGridView
intnewPageIndex=0;

if(-2==e.NewPageIndex)
{//whenclickthe"GO"Button
TextBoxtxtNewPageIndex=null;
//GridViewRowpagerRow=theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count-1]asGridViewRow;//refertoPagerTemplate
GridViewRowpagerRow=theGrid.BottomPagerRow;//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow或者TopPagerRow,当然还增加了HeaderRow和FooterRow
//updatedat2006年6月21日3:15:33

if(null!=pagerRow)
{
txtNewPageIndex=pagerRow.FindControl("txtNewPageIndex")asTextBox;//refertotheTextBoxwiththeNewPageIndexvalue
}

if(null!=txtNewPageIndex)
{
newPageIndex=int.Parse(txtNewPageIndex.Text)-1;//gettheNewPageIndex
}
}
else
{//whenclickthefirst,last,previousandnextButton
newPageIndex=e.NewPageIndex;
}

//checktopreventformtheNewPageIndexoutoftherange
newPageIndex=newPageIndex<0?0:newPageIndex;
newPageIndex=newPageIndex>=theGrid.PageCount?theGrid.PageCount-1:newPageIndex;

//specifytheNewPageIndex
theGrid.PageIndex=newPageIndex;

}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com