AspNetPager分页控件之url重写

          园子里关于AspNetPager分页控件的文章很多,最近喵喵在项目中使用到了这个控件,现将AspNetPager url重写的使用分享一下。

如图:http://www.XXXX/

type代表类型,pgid代表当前页码。

      int  currentPageId  =  Convert.ToInt32(Request.QueryString[ " pgid " ].ToString());
                ViewState[
" currentPageId " =  currentPageId;
                
if  (Session[ " ptype " ==   null )
                {
                    Session[
" ptype " =   string .Empty;
                }

                
if  (Request.QueryString[ " tag " !=   null   &&  Request.QueryString[ " tag " !=   "" )
                {
                    
this .AspNetPager1.UrlRewritePattern  =   " listproduct/tag_{tag}_pgid_{0}.html " .Replace( " {tag} " , Request.QueryString[ " tag " ]);
                    
string  tag  =  Server.HtmlDecode(Request.QueryString[ " tag " ].ToString());
                    Session[
" Where " =   " proe.ProcTitle like '% "   +  tag  +   " %' " ;
             
                    txtProduceName.Text 
=  tag;
                }
                
else   if  (Request.QueryString[ " type " !=   null   &&  Request.QueryString[ " type " !=   "" )
                {
                    
this .AspNetPager1.UrlRewritePattern  =   " listproduct/type_{type}_pgid_{0}.html " .Replace( " {type} " , Request.QueryString[ " type " ]);
                    
string  type  =  Request.QueryString[ " type " ];
                    
if  (type.Equals( " product " ))  // 表示所有的产品类型
                    {
                        Session[
" Where " =   string .Empty;
                    }
                    
else
                    {
                        Session[
" Where " =   "  proe.ProductType like ' "   +  type  +   " %'                        this.SelectThType1.Value = type;
                    }

 

一些属性需读者自己参考吴旗娃官方网址查阅。

1.上面的代码根据传过来的参数,然后指定分页控件的UrlRewritePattern。写在Page_Load里。

 

ExpandedBlockStart.gif code
    protected   void  AspNetPager1_PageChanged( object  src, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex 
=  Convert.ToInt32(ViewState[ " currentPageId " ].ToString());
        
this .PageDataBind();
    }

 

 

2.上面的代码是它的绑定数据的事件。

 

 

 

  public   void  PageDataBind()
    {
        
try
        {
            
this .dlProducts.DataSource  =   null ;
            
if  (Session[ " Where " ==   null )
            {
                Session[
" Where " =   "" ;
            }
            
if  (Session[ " Where " ].ToString().Length  >   0 )
            {
                
this .AspNetPager1.RecordCount  =  GetProduceSizeBySQL(Session[ " Where " ].ToString());
            }
            
else
            {
                
this .AspNetPager1.RecordCount  =  GetProductSize();
            }

            
string [] list  =   new   string [] {  " * " " Produce as proe inner join companyinfo as comp  "   +
        
" on proe.UserId=comp.UserId  " , Session[ " Where " ].ToString(),  " proe.Id  " "  order by proe.SendTime  desc  " , ViewState[ " currentPageId " ].ToString(),  " 15 "  };

            
// Response.Write(list.GetValue(0) + "___" + list.GetValue(1) + "___" + list.GetValue(2) + "___" + list.GetValue(3) + "___" + list.GetValue(4) + "___" + list.GetValue(5) + "___");

            AspNetPager1.CurrentPageIndex 
=  Convert.ToInt32(ViewState[ " currentPageId " ].ToString());
            dlProducts.DataSource 
=  ProduceManage.GetProductsByProc(list);
            dlProducts.DataBind();
        }
        
catch  (Exception)
        {
        }
    }

 

 

3.上面的代码通过存储过程返回当前页的数据给数据源控件。

 

   < webdiyer:AspNetPager ID = " AspNetPager1 "  CssClass = " anpager "  CurrentPageButtonClass = " cpb "
                    PageSize
= " 15 "  runat = " server "  HorizontalAlign = " Center "  Width = " 100% "  
                    EnableUrlRewriting
= " true "  UrlRewritePattern = " listproduct/type_{type}_pgid_{0}.html "
                    OnPageChanged
= " AspNetPager1_PageChanged "  FirstPageText = " 首页 "  LastPageText = " 尾页 "
                   NextPageText
= " 下一页 "  PrevPageText = " 上一页 "  CustomInfoHTML = " 第<font color='red'><b>%currentPageIndex%</b></font>页/共%PageCount%页   每页%PageSize%条/共/%RecordCount%条 "  ShowPageIndexBox = " Always "  ShowCustomInfoSection = " Right "  CustomInfoSectionWidth = " 250px " >
                
</ webdiyer:AspNetPager >

 

 

4.上面的代码是页面中控件的属性设置。

 

好了,关于AspNetPager分页控件的url重写今天就写到这里,喵喵在这里谢谢您的支持!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值