博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AspNetPager分页控件之url重写
阅读量:6950 次
发布时间:2019-06-27

本文共 3192 字,大约阅读时间需要 10 分钟。

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

如图:/

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重写今天就写到这里,喵喵在这里谢谢您的支持!

转载地址:http://vhkil.baihongyu.com/

你可能感兴趣的文章
使用Sklearn进行数据挖掘
查看>>
怎么估算空间利用率?新研发传感器分分钟搞定!
查看>>
搞大啦!精灵云与全球最大孵化器PNP带你一起飞
查看>>
第一章代码重构
查看>>
【益智题】十块钱去哪了?
查看>>
静态密码已经"OUT" 探索身份验证新方式
查看>>
轻松搞定RabbitMQ(四)——发布/订阅
查看>>
projecteuler_problem12
查看>>
VN2VN——中小企业的网络融合之道
查看>>
数百亿的新疆安防市场,集成巨头告诉你如何才能从中分杯羹
查看>>
[译] REST API 已死,GraphQL 长存
查看>>
学点PYTHON基础的东东--数据结构,算法,设计模式---访问者模式
查看>>
独家 | 陆化普:大数据、AI解决交通管理难题的新思路
查看>>
你需要的不是大数据 而是正确的数据~
查看>>
我只能说,Spring Data REST真的很燥辣
查看>>
使用短生命周期容器(Ephemeral Containers)构建微服务化的工作流
查看>>
R语言领跑 大数据岗位霸占IT薪酬榜单
查看>>
靠播放业务吃不饱?音乐流媒体纷纷“加电商”卖周边
查看>>
SSL之父称SSL不会因被攻击而失去生命力
查看>>
解读对象存储九大关键特征
查看>>