asp.net ajax repeater 无刷新 自定义分页

<%--<%@ 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>
--%>

posted on 2007-11-28 19:41 top15from_old1 阅读(...) 评论(...) 编辑 收藏

导航

公告

随州简爱保罗定制衣柜专卖店为您准备了全套家装所需的定制家具,用工厂直销的价格和衣柜行业领导品牌的实力恭候您的光临。 随州市清河路清河丽景大门右侧18307228966 0722-3594778