日期:2014-05-19  浏览次数:20540 次

e.NewPageIndex; 分页
this.GridView1.PageIndex   =   e.NewPageIndex;
                this.GridView1.DataBind();

分页功能,当我点击页码之后,总是一片空白,不进行显示。

------解决方案--------------------
指定一个数据源懂吗?
this.GridView1.PageIndex = e.NewPageIndex;

this.GridView1.datasource = DateSet;
this.GridView1.DataBind();
------解决方案--------------------
手写翻页

protected void datagridbind(bool NeedReCount) //NeedReCount = true 需要重新计算记录数量
{
dg_Modal.DataSource = null;
try
{
//首先,计算出记录条数
string sqlstring;
sqlstring = "select * from Tb_Menus ";

//获得记录个数
if (NeedReCount)//如果需要重新计算记录个数
{
if (ViewState[ "Quary "].ToString().Trim() != " " && ViewState[ "Quary "].ToString().Trim() != null)
{ //如果是有查询条件
sqlstring = sqlstring + " where 1=1 " + ViewState[ "Quary "].ToString();
}

//将计算出来的记录个数保存到viewstate变量中
ViewState[ "recordcount "] = DbHelperSQL.GetRecordCount(sqlstring);
//既然已经重新计算页面记录个数,则应该把当前页面设置到第一页
ViewState[ "pageindex "] = 1;
}


int pagesize=5; //每页显示的记录个数
recordcount = Convert.ToInt32(ViewState[ "recordcount "].ToString());

if (recordcount!=0)
{//如果有数据,则显示
lbl_empty.Visible=false;
dg_Modal.Visible=true;
pageindex=Convert.ToInt32(ViewState[ "pageindex "]);
//获取页面数量
if ((recordcount%pagesize)==0)
{
pagenum=recordcount/pagesize;
}
else
{
pagenum=(recordcount/pagesize+1);
}
//如果传递过来的page页面数大于总页数,则默认到最大页数
if (pageindex> pagenum)
{
pageindex=pagenum;
ViewState[ "pageindex "]=pagenum;
}



//关键翻页语句
//将sql语句变量清空(与上面的查询记录条数的sql变量复用)
sqlstring = " ";

if (ViewState[ "Quary "] != null && ViewState[ "Quary "].ToString().Trim() != " ")
{ //如果是有查询条件
sqlstring = "select top "+pagesize
+ " * "
+ " from Tb_Menus "
+ " where [MenuID] not in "
+ " (select top "+pagesize * (pageindex-1)+ " [MenuID] "
+ " from Tb_Menus "
+ " where 1=1 " + ViewState[ "Quary "].ToString().Trim()
+ " order by MenuID asc) "
+ ViewState[ "Quary "].ToString().Trim()
+ " order by MenuID asc ";
}
else
{//如果是没有查询条件
sqlstring = "select top "+pagesize
+ " * "
+ " from Tb_Menus "
+ " where [MenuID] not in "
+ " (select top "+pagesize * (pageindex-1)+ " [MenuID] "
+ " from Tb_Menus "
+ " order by MenuID asc) "
+ " order by MenuID asc ";
}
//取得页面显示的数据
dg_Modal.DataSource = DbHelperSQL.Query(sqlstring);//sqloper.dsFill(sqlstring);
dg_Modal.DataBind();
//以下是设置按钮显示状态 比如如果最后一页,则“下一页”不能显示

Pager.btnlink(pagenum,pageindex,btnfirst,btnprev,btnnext,btnlast);
lblyc.Text=Convert.ToString(pageindex)+ "/ &qu