用aspnetpager实现datalist分页

微软的Datalist在做电子相册时候必不可少,但是不支持分页功能,都出到2008了还是没有分页功能,幸好网上有个专业的分页空间aspnetpager,帮我们解决了大问题,说实在话的,网上关于datalist分页的办法很多,但是我觉得都不是很简单实用,有的是url提交,有的是存储过程分页,一个字不方便。下面就是aspnetpager的分页,代码。

1.首先下载aspnetpager控件,http://www.webdiyer.com/download/default.aspx

2.在工具箱里面添加aspnetpager控件。

3.前台引用

 

 

   < asp:DataList runat = " server "  ID = " dlPicList "  Width = " 100% "  Border = " 0 "  CellSpacing = " 0 "  CellPadding = " 0 "   RepeatColumns = " 4 "  RepeatDirection = " Horizontal " >
    
< ItemTemplate >
       
< a href = ' <%# "PicView.aspx?PicID="+Eval("PicID")%> ' >< asp:Image ID = " imPic "  runat = " server "  ImageUrl = ' <%# Bind("PicUrl")%> '  width = " 104 "  height = " 76 "  BorderWidth = " 1 "   />< br  />
                          
< asp:Label runat = " server "  ID = " lblTitle "   Text = ' <%# Bind("DisTitle")%> ' ></ asp:Label ></ a >
    
</ ItemTemplate >
    
< ItemStyle CssClass = " word_green "  HorizontalAlign = " Center "   />
    
</ asp:DataList >
   
< webdiyer:AspNetPager ID = " AspNetPager1 "  runat = " server "    PageSize = " 5 "   ShowBoxThreshold = " 1 "  AlwaysShow = " True "  FirstPageText = " 首页 "  LastPageText = " 末页 "
NextPageText
= " 下一页 "  PrevPageText = " 上一页 "   onpagechanging = " AspNetPager1_PageChanging " >
  
</ webdiyer:AspNetPager >

 

 

 4.后台代码

 

 

protected   void  Page_Load( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
{
            
if (!IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                BindData();
            }

        }


        
private   void  BindData()
ExpandedBlockStart.gifContractedBlock.gif        
{
         
            conn 
= ConfigurationManager.ConnectionStrings["STRING_SqlConn"].ToString();
ExpandedSubBlockStart.gifContractedSubBlock.gif            
object[] para = 0, picid };
            DataTable dt 
= DataOperator.TableUseTrans(conn, "SP_Pic_GetView", para);
            DataView dv 
= dt.DefaultView;
            
//对用于分页的类的引用
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource 
= dv;//设置数据源(DataTable类型)
            pds.AllowPaging = true;
            
//每页显示的行数
            
//pds.PageSize = 12;
            
          
            AspNetPager1.RecordCount 
= dv.Count;
            pds.CurrentPageIndex 
= AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize 
= AspNetPager1.PageSize;
            dlPicList.DataSource
= pds;
            dlPicList.DataBind();
            

        }


        
protected   void  AspNetPager1_PageChanging( object  src, Wuqi.Webdiyer.PageChangingEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
{
            AspNetPager1.CurrentPageIndex 
= e.NewPageIndex;
            BindData();
        }


转载于:https://www.cnblogs.com/VisualStudio/archive/2008/10/15/1311409.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值