asp.net ajax repeater 無重新整理 自訂分頁

來源:互聯網
上載者:User

<%--<%@ Control Language="C#" ClassName="reppage" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
    PagedDataSource ps;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {  
            List<Class1> cl = getmess();
            ps= new PagedDataSource();
            ps.DataSource = cl;
            ps.AllowPaging = true;
            ps.PageSize = 2;
           // Session["p"] = ps;
            Cache.Insert("Reps", ps);       

            r.DataSource = (PagedDataSource)Cache["Reps"];
            r.DataBind();

            Repeater1.DataSource = (PagedDataSource)Cache["Reps"];
            Repeater1.DataBind();

            Repeater2.DataSource = (PagedDataSource)Cache["Reps"];
            Repeater2.DataBind();

            lblsum.Text = ps.DataSourceCount.ToString();
            lblS.Text = ps.PageCount.ToString();     
        }
    }
    public List<Class1> getmess()
    {
        List<Class1> clss = new List<Class1>();
        using(SqlDataReader dr=SqlHelper.ExecuteReader(SqlHelper.sqlstr,CommandType.Text,"select *from exTable",null))
        {
            while (dr.Read())
            {
                Class1 cls = new Class1(dr.GetInt32(0), dr.GetString(1), dr.GetString(2));
                clss.Add(cls);
            }
        }
        return clss;
    }

    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        if (Cache["Reps"] != null)
        {
            ps = (PagedDataSource)Cache["Reps"];
        }
        else
        {
            List<Class1> cl = getmess();
            ps = new PagedDataSource();
            ps.DataSource = cl;
            Cache.Insert("Reps", ps);
            ps = (PagedDataSource)Cache["Reps"];
        }
        if (!ps.IsLastPage)
        {
            ps.CurrentPageIndex++;
            r.DataSource = ps;
            r.DataBind();
        }
        lblN.Text = ps.CurrentPageIndex + 1 + "";   
        //if (Session["p"] != null)
        //{
        //    ps = (PagedDataSource)Session["p"];
        //    if (!ps.IsLastPage)
        //    {               
        //        ps.CurrentPageIndex++;
        //        r.DataSource = ps;
        //        r.DataBind();
        //    }
        //    lblN.Text = ps.CurrentPageIndex + 1 + "";
        //} 
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        if (Cache["Reps"] != null)
        {
            ps = (PagedDataSource)Cache["Reps"];
        }
        else
        {
            List<Class1> cl = getmess();
            ps= new PagedDataSource();
            ps.DataSource = cl;           
            Cache.Insert("Reps",ps);
            ps = (PagedDataSource)Cache["Reps"];
        }
        ps.CurrentPageIndex = ps.PageCount - 1;
        r.DataSource = ps;
        r.DataBind();
        lblN.Text = ps.PageCount.ToString(); 
         
        //if (Session["p"] != null)
        //{           
        //    ps = (PagedDataSource)Session["p"];
        //    ps.CurrentPageIndex = ps.PageCount - 1;
        //    r.DataSource = ps;
        //    r.DataBind();
        //    lblN.Text = ps.PageCount.ToString();        
        //}     
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Cache["Reps"] != null)
        {
            ps = (PagedDataSource)Cache["Reps"];
        }
        else
        {
            List<Class1> cl = getmess();
            ps = new PagedDataSource();
            ps.DataSource = cl;
            Cache.Insert("Reps", ps);
            ps = (PagedDataSource)Cache["Reps"];
        }
        ps.CurrentPageIndex = 0;
        r.DataSource = ps;
        r.DataBind();
        lblN.Text = "1";   
        //if (Session["p"] != null)
        //{           
        //    ps = (PagedDataSource)Session["p"];
        //    ps.CurrentPageIndex = 0;
        //    r.DataSource = ps;
        //    r.DataBind();
        //    lblN.Text = "1";    
        //}                
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        if (Cache["Reps"] != null)
        {
            ps = (PagedDataSource)Cache["Reps"];
        }
        else
        {
            List<Class1> cl = getmess();
            ps = new PagedDataSource();
            ps.DataSource = cl;
            Cache.Insert("Reps", ps);
            ps = (PagedDataSource)Cache["Reps"];
        }
        if (!ps.IsFirstPage)
        {
            ps.CurrentPageIndex--;
            r.DataSource = ps;
            r.DataBind();
        }
        lblN.Text = ps.CurrentPageIndex + 1 + "";
        //if (Session["p"] != null)
        //{
        //    ps = (PagedDataSource)Session["p"];
        //    if (!ps.IsFirstPage)
        //    {               
        //        ps.CurrentPageIndex--;
        //        r.DataSource = ps;
        //        r.DataBind();
        //    }
        //    lblN.Text = ps.CurrentPageIndex + 1 + "";
        //}   
    }
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
 <asp:Repeater ID="r" runat=server Visible="False">
   <HeaderTemplate><table width=500><tr><td>ID</td><td>PAGE</td><td>Source</td></tr></HeaderTemplate>
   <ItemTemplate><tr>
   <td><%#Eval("exID")%></td>
   <td><%#Eval("exPage")%></td>
   <td><%#Eval("exMessage")%></td>
   </tr></ItemTemplate>
   <FooterTemplate></table></FooterTemplate>
 </asp:Repeater>
 <asp:Repeater ID="Repeater1" runat=server>
   <HeaderTemplate><table width=500><tr><td>ID</td><td>PAGE</td><td>Source</td></tr></HeaderTemplate>
   <ItemTemplate><tr>
   <td><%#Eval("exID")%></td>
   <td><%#Eval("exPage")%></td>
   <td><%#Eval("exMessage")%></td>
   </tr></ItemTemplate>
   <FooterTemplate></table></FooterTemplate>
 </asp:Repeater>
 <asp:Repeater ID="Repeater2" runat=server>
   <HeaderTemplate><table width=500><tr><td>ID</td><td>PAGE</td><td>Source</td></tr></HeaderTemplate>
   <ItemTemplate><tr>
   <td><%#Eval("exID")%></td>
   <td><%#Eval("exPage")%></td>
   <td><%#Eval("exMessage")%></td>
   </tr></ItemTemplate>
   <FooterTemplate></table></FooterTemplate>
 </asp:Repeater>
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">首頁</asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">上一頁 </asp:LinkButton>
    <asp:LinkButton ID="LinkButton3" runat="server" OnClick="LinkButton3_Click">下一頁</asp:LinkButton>
    <asp:LinkButton ID="LinkButton4" runat="server" OnClick="LinkButton4_Click">尾頁</asp:LinkButton>&nbsp; 共
    <asp:Label ID="lblsum" runat="server"></asp:Label>
    條資料 當前第<asp:Label ID="lblN" runat="server"></asp:Label>頁 總共<asp:Label ID="lblS" runat="server"></asp:Label>頁
</ContentTemplate>
</asp:UpdatePanel>
--%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.