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