大哥们,请问写DataList的分页代码的时候,怎么获得记录的总数?
就是怎么实现:“共/页”?
谢谢了~ 急死我了
来人解决一下吧
不会都去水区了吧~~~`
问题解决了,自己搞了好久~
把代码贴出来,希望对大家能有帮助
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = ds.Tables[0].DefaultView;
objPds.AllowPaging = true;
objPds.PageSize = 6;
int CurPage;
int RecordNum = ds.Tables[0].Rows.Count;
int PageNum;
//当前页面从Page查询参数获取
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
if (RecordNum % 6 == 0) //PageSize=6;
{
PageNum = RecordNum / 6;
}
else
{
PageNum = (RecordNum / 6)+1;
}
objPds.CurrentPageIndex = CurPage - 1;
Label1.Text = PageNum.ToString();
//if (objPds.IsFirstPage)
// HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage+1);
if (!objPds.IsLastPage)
HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage+1);
if (objPds.IsLastPage)
HyperLink1.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage);
DataListLogo.DataSource = objPds;
DataListLogo.DataBind();
//关闭数据库;
SqlDataAdapterLoad = null;
SqlConnectionLoad.Close();
SqlConnectionLoad = null;