protected void Page_Load(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
context.User.Identity.
if(!IsPostBack)
{
currPage.Text="";
bindData();
} }
protected void bindData()
{
///获取数据
string sql = "select * from SA_Tree";
SqlConnection con = new SqlConnection(connectStr);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
da.Fill(ds,"test"); //实例化数据绑定控件
PagedDataSource ps = new PagedDataSource();
ps.AllowPaging = true;//设置允许分页
ps.DataSource = ds.Tables["test"].DefaultView;//设置数据源
ps.PageSize = ;//设置每页显示的行数 ps.CurrentPageIndex = Convert.ToInt32(currPage.Text) - ;//设置当前页索引 totalPage.Text = ps.PageCount.ToString();
//判断当前页是否为首页
if (ps.IsFirstPage)
{
BtnPre.Enabled = false;
}
else
{
BtnPre.Enabled = true;
}
//判断当前页是否为最后一页
if (ps.IsLastPage)
{
BtnNext.Enabled = false;
}
else
{
BtnNext.Enabled = true;
}
Repeater1.DataSource = ps;
Repeater1.DataBind();
} protected void BtnFirst_Click(object sender, EventArgs e)
{
currPage.Text = "";
bindData();
}
protected void BtnNext_Click(object sender, EventArgs e)
{
currPage.Text = (Convert.ToInt32(currPage.Text)+).ToString();
bindData();
}
protected void BtnLast_Click(object sender, EventArgs e)
{
currPage.Text = totalPage.Text;
bindData();
}
protected void BtnPre_Click(object sender, EventArgs e)
{
currPage.Text = (Convert.ToInt32(currPage.Text) - ).ToString();
bindData();
}
服务端
<form id="form1" runat="server">
<div>
<span>
<asp:Label ID="currPage" runat="server"></asp:Label>/<asp:Label ID="totalPage" runat="server"></asp:Label></span>
</div>
<div>
<asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate>
<table class="Treelist">
<tr>
<th>节点ID</th>
<th>节点名称</th>
<th>父节点</th>
<th></th>
</tr> </HeaderTemplate>
<ItemTemplate>
<tr>
<th><%# Eval("NodeID") %></th>
<th><%# Eval("TreeText") %></th>
<th><%# Eval("ParentID") %></th>
<th></th>
</tr>
</ItemTemplate>
<FooterTemplate> </table>
</FooterTemplate>
</asp:Repeater>
<table>
<tr> <td><asp:Button ID="BtnFirst" runat="server" Text="首页" OnClick="BtnFirst_Click"/></td>
<td><asp:Button ID="BtnPre" runat="server" Text="上一页" OnClick="BtnPre_Click"/></td>
<td><asp:Button ID="BtnNext" runat="server" Text="下一页" OnClick="BtnNext_Click" /></td>
<td><asp:Button ID="BtnLast" runat="server" Text="尾页" OnClick="BtnLast_Click"/></td>
</tr>
</table> </div>
</form>
客户端