我在具有listview控件和datapager的页面上使用Intelligencia.UrlRewriter。数据分页工作正常,但寻呼机使用真实的URL而不是重写的。
如果URL重写为:
/products-page-1.aspx?page=2
真正的网址:
/products.aspx?id=1
寻呼机使用/products.aspx?id=1&page=2
我希望能够设置它以便寻呼机使用:
/products-page-1.aspx?page=2
我在网上找到了一些信息,并使用以下功能:
protected void VideosDataPager_PreRender(object sender, EventArgs e)
{
DataPager pager = (DataPager)Page.FindControl("VideosDataPager");
int count = pager.TotalRowCount;
int pageSize = pager.PageSize;
int pagesCount = count / pageSize + (count % pageSize == 0 ? 0 : 1);
int pageSelected = pager.StartRowIndex / pageSize + 1;
for (int i = 1; i <= pagesCount; ++i)
{
if (pageSelected != i)
{
HyperLink link = new HyperLink();
link.NavigateUrl = "/products--page--" + catnameforPaging + "--1.aspx?p=" + i.ToString();
link.Text = i.ToString();
VideosList.Controls.Add(link);
}
else
{
Literal lit = new Literal();
lit.Text = i.ToString();
VideosList.Controls.Add(lit);
}
Literal space = new Literal();
space.Text = " ";
VideosList.Controls.Add(space);
}
}
但有了这个,我得到2个数据页,如果我从页面中删除了VideosDataPager,该功能就会停止工作。
有没有办法在datapager上更改目标网址?
答案 0 :(得分:0)
用
修复protected void VideosDataPager_PreRender(object sender, EventArgs e)
{
DataPager pager = (DataPager)Page.FindControl("VideosDataPager");
pager.Controls.Clear();
int count = pager.TotalRowCount;
int pageSize = pager.PageSize;
int pagesCount = count / pageSize + (count % pageSize == 0 ? 0 : 1);
int pageSelected = pager.StartRowIndex / pageSize + 1;
if (pageSelected>1)
{
// first page
HyperLink img = new HyperLink();
img.ImageUrl = "/images/first.png";
img.Text = "First page";
img.NavigateUrl = "/videos--cat--" + catnameforPaging + "--1.aspx?s="+ NvUtils.GetCurrentSessionKey();
VideosList.Controls.Add(img);
// gap
Literal space = new Literal();
space.Text = " ";
VideosList.Controls.Add(space);
}
// paging
for (int i = 1; i <= pagesCount; ++i)
{
if (pageSelected != i)
{
HyperLink link = new HyperLink();
link.NavigateUrl = "/videos--cat--" + catnameforPaging + "--1.aspx?s="+ NvUtils.GetCurrentSessionKey()+"&p=" + i.ToString();
link.Text = i.ToString();
VideosList.Controls.Add(link);
}
else
{
Literal lit = new Literal();
lit.Text = i.ToString();
VideosList.Controls.Add(lit);
}
Literal spaceb = new Literal();
spaceb.Text = " ";
VideosList.Controls.Add(spaceb);
}
if (pageSelected < pagesCount)
{
// last page
HyperLink imgb = new HyperLink();
imgb.ImageUrl = "/images/last.png";
imgb.Text = "Last page";
imgb.NavigateUrl = "/videos--cat--" + catnameforPaging + "--1.aspx?s=" + NvUtils.GetCurrentSessionKey() + "&p=" + pagesCount;
VideosList.Controls.Add(imgb);
}
}