views:

547

answers:

2

Hi, i am using Intelligencia.UrlRewriter on a page that has a listview control and datapager. Data paging works fine but pager uses real url instead of rewritten one.

if url rewrite is /products-page-1.aspx?page=2

and real url

/products.aspx?id=1

pager uses /products.aspx?id=1&page=2

i want to be able to set it so pager uses /products-page-1.aspx?page=2

I have found some info on the net and got it working with below function

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);
   }

}

but with this i get 2 datapagin and if i remove VideosDataPager from the page function stops working.

Is ther any way to change target url on datapager?

A: 

fixed with

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);
   }

}

A: 

Hi!!

              I have also used URL Rewriter (Intelligencia.URLRewriter) I have also used it with datagrid you can use Hyperlink to point the page. see [http://www.gsmunlockintl.com][1]

Regards, Milind Kansagara