62,268
社区成员
发帖
与我相关
我的任务
分享
string sql = "select * from jj_news where" + sqlPrm + " order by adddate desc";
//Response.Write(sql);
DataTable dt = dal.ExecDataTablebySql(sql);
PagedDataSource ps = new PagedDataSource();
ps.AllowPaging = true;
ps.DataSource = dt.DefaultView;
ps.PageSize = 25;
int pagecount;
if (Request.QueryString["page"] != null)
pagecount = Convert.ToInt32(Request.QueryString["page"].ToString());
else
pagecount = 1;
ps.CurrentPageIndex = pagecount - 1;
lblPagecount.Text = ps.PageCount.ToString();
lblList.Text = "";
int MinPage = pagecount - 5;
int MaxPage = pagecount + 5;
if (MaxPage > ps.PageCount)
MaxPage = ps.PageCount;
if (MinPage < 0)
MinPage = 0;
string strpath = "";
string strparam = "";
if (Request.Url.ToString().IndexOf('?') != -1)
{
strparam = "&" + ((Request.Url.ToString()).Split('?'))[1].ToString();
strparam = strparam.Replace("&oldPage=", "");
strparam = strparam.Replace("&Page", "&oldPage");
strpath = ((Request.Url.ToString()).Split('?'))[0].ToString();
}
//Response.Write(MinPage +"/"+ MaxPage);
for (int i = MinPage; i < MaxPage; i++)
{
string url = strpath + "?Page=" + Convert.ToString(i + 1) + strparam;
string pg = Convert.ToString(i + 1);
string style1 = "";
if (i == pagecount - 1)
style1 = "style='background:#FFCC33;'";
lblList.Text += "<div class='pageNum' " + style1 + " ><a href=" + url + " > " + pg + " </a></div> ";
}
lblList.Text += "...";
//Response.Write(ts.Rows[0][0]);
if (!ps.IsFirstPage)
this.hplFist.NavigateUrl = strpath + "?Page=" + Convert.ToString(1) + strparam;
if (!ps.IsFirstPage)
this.hplPrv.NavigateUrl = strpath + "?Page=" + Convert.ToString(pagecount - 1) + strparam;
if (!ps.IsLastPage)
this.hplNext.NavigateUrl = strpath + "?Page=" + Convert.ToString(pagecount + 1) + strparam;
if (!ps.IsLastPage)
this.hplLast.NavigateUrl = strpath + "?Page=" + Convert.ToString(ps.PageCount) + strparam;
RepNewsList.DataSource = ps;
RepNewsList.DataBind();