AspNetPager的使用 1 (分页存储过程) AspNetPager 分页2(普通分页)

AspNetPager的使用 1 (分页存储过程)
2008-04-29 下午 09:35
其使用是通过储存过程来实现的
储存过程如下:
CREATE Procedure     Pr_AritleAllInfo
(@PageSize int,
@PageIndex int,
@Docount bit)
As
Set nocount on
If(@docount=1)
Select count(*) from Aritle
Else
Begin
Declare @indextable table(id int identity(1,1) , KeyNo uniqueidentifier)
Declare @PageLowerBound int
Declare @PageUpperBound int
Set @PageLowerBound=(@PageIndex-1)*@PageSize
Set @PageUpperBound=@PageLowerBound+@PageSize
Set RowCount @PageUpperBound
Insert into @indextable(KeyNo) select KeyNo From Aritle order by AddTime desc
Select O.* from Aritle O,@indextable t where O.KeyNo=t.KeyNo
And t.id>@PageLowerBound and t.id<
=@PageUpperBound order by t.id
End
GO
Default.apx页面:
<%@ Register TagPrefix="cc1" Namespace="Wuqi.Webdiyer" Assembly="aspnetpager" %>
< center >
        <asp:DataList ID="DataList1" runat="server">
        <HeaderTemplate><table width="760"  border="0" cellspacing="0" cellpadding="0" style="border-bottom:1px dotted #ccc;"  id="table5" ></HeaderTemplate>
        <ItemTemplate >
        <tr>
        <td> <%#Eval("title") %></td>
        </tr></ItemTemplate>
        <FooterTemplate ></table></FooterTemplate>
        </asp:DataList>
        <table border="0" cellpadding="0" style="border-collapse: collapse; background-color: #f5f5f5;" width="760" id="table1" class="mu6" height="20">
    <tr>
       <td style="height: 25px">
         <Webdiyer:AspNetPager id="Pager" runat="server" HorizontalAlign="Right"  FirstPageText="<<" LastPageText=">>" PrevPageText="<" NextPageText=">" NumericButtonTextFormatString="-{0}-" Width="760px"
           ShowCustomInfoSection="Left" ShowBoxThreshold="2" PageSize="5" OnPageChanged="pager_PageChanged" InputBoxClass="text2" TextAfterInputBox=""  />
           </td>
    </tr>
</ table >
        </center>
2007/08/01 15:45
Default.aspx.cs
public partial class Page : System.Web.UI.Page
{
    public SqlConnection Conn;
    public SqlCommand Cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        String ConnString = DataConn.connetionString;
        Conn = new SqlConnection(ConnString);
        if (!IsPostBack)
        {
            FristBind();
        }
    }
    protected void FristBind()
    {
        Cmd = new SqlCommand("Pr_AritleAllInfo", Conn);
        Cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter ParaPageIndex = new SqlParameter("@PageIndex", SqlDbType.Int);
        ParaPageIndex.Value = 1;
        Cmd.Parameters.Add(ParaPageIndex);
        SqlParameter ParaPageSize = new SqlParameter("@PageSize", SqlDbType.Int);
        ParaPageSize.Value = 1;
        Cmd.Parameters.Add(ParaPageSize);
        SqlParameter ParaDocount = new SqlParameter("@Docount", SqlDbType.Bit);
        ParaDocount.Value = true;
        Cmd.Parameters.Add(ParaDocount);
        Conn.Open();
        Pager.RecordCount = (int)Cmd.ExecuteScalar();
        Conn.Close();
        BindDataList();
    }
    protected void BindDataList()
    {
        Cmd = new SqlCommand();
        Cmd.Connection = Conn;
        Cmd.CommandType = CommandType.StoredProcedure;
        Cmd.CommandText = "Pr_AritleAllInfo";
        SqlParameter ParaPageIndex=new SqlParameter ("@PageIndex",SqlDbType .Int );
        ParaPageIndex.Value =Pager .CurrentPageIndex ;
        Cmd .Parameters .Add (ParaPageIndex );
        SqlParameter ParaPageSize = new SqlParameter("@PageSize",SqlDbType .Int);
        ParaPageSize.Value = Pager.PageSize ;
        Cmd.Parameters.Add(ParaPageSize);
        SqlParameter ParaDocount = new SqlParameter("@Docount", SqlDbType.Bit);
        ParaDocount.Value = false;
        Cmd.Parameters.Add(ParaDocount);
        Conn.Open();
        DataList1.DataSource = Cmd.ExecuteReader();
        DataList1.DataBind();
        Conn.Close();
        AddCustomText();
    }
    public void AddCustomText()
    {
        Pager.CustomInfoText = " 文章总数:<font color=/"blue/"><b>" + Pager.RecordCount.ToString() + "</b></font>";
        Pager.CustomInfoText += " 总页数:<font color=/"blue/"><b>" + Pager.PageCount.ToString() + "</b></font>";
        Pager.CustomInfoText += " 当前页:<font color=/"red/"><b>" + Pager.CurrentPageIndex.ToString() + "</b></font>";
    }
    protected void pager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
    {
        Pager.CurrentPageIndex = e.NewPageIndex;
        BindDataList();
    }
AspNetPager  分页2(普通分页)

<%@ Register TagPrefix="cc1" Namespace="Wuqi.Webdiyer" Assembly="aspnetpager" %>

<cc1:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" OnPageChanged="AspNetPager1_PageChanged" PageSize="10" style="display: inline">
</cc1:AspNetPager>

 

public void DataGridBind()
        {
            string SCondition = "";
         
            this.AspNetPager1.RecordCount =baseOperate.GetTableListCountByTableName("Tbl_ExamOperKnowSort", SCondition);
            DataTable dt = baseOperate.GetTableListByTableName("Tbl_ExamOperKnowSort", AspNetPager1.CurrentPageIndex - 1, AspNetPager1.PageSize, SCondition);
            this.DataGrid1.DataSource = dt;
            this.DataGrid1.DataBind();  
           
            AspNetPager1.CustomInfoText = "记录总数:<font color=/"blue/"><b>" + AspNetPager1.RecordCount.ToString() + "</b></font>";
            AspNetPager1.CustomInfoText += " 总页数:<font color=/"blue/"><b>" + AspNetPager1.PageCount.ToString() + "</b></font>";
            AspNetPager1.CustomInfoText += " 当前页:<font color=/"red/"><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>"                
          
        }

protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.DataGridBind();
        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值