2 u012226150 u012226150 于 2013.11.07 16:40 提问

Repater 无法实现分页效果

public DataSet getArticle(string sql)
{
CheckConnection();
try
{
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
con.Close();
}
}

.cs代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FormatNjuTable;

public partial class Default4 : System.Web.UI.Page
{

DBbase db = new DBbase();
protected int pagesize;
 string sql = "select Title,Author,key1,UpdateTime,content,ArticleID,DefaultPicUrl from dbo.Article  where ArticleID="+id+"  AND  Elite=1  and ClassID=362 and Passed=1 order by UpdateTime desc";
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        int id = int.Parse(Request.QueryString["cid"].ToString());

        //this.Repeater1.DataSource = BTNews.gettzgg(id);
        //this.Repeater1.DataBind();
        this.Bind();
    }

}
public void Bind()
{
    //获取当前页的页码
    int curpage = Convert.ToInt32(this.lblPage.Text);
    //使用PageDataSource类实现Repeater控件的分页功能
    PagedDataSource ps = new PagedDataSource();
    //Session["id"] = Request.QueryString["sort"].ToString();
    //M_bc.B_id = Convert.ToInt32(Session["id"].ToString());
    //获取数据集
    int id = int.Parse(Request.QueryString["cid"].ToString());
    DataSet ds = db.getArticle(sql);
    ps.DataSource = ds.Tables[0].DefaultView;
    //是否可以分页
    ps.AllowPaging = true;
    //显示的数量
    ps.PageSize =8;
    //取得当前页的页码
    ps.CurrentPageIndex = curpage - 1;
    this.lb_up.Enabled = true;
    this.lb_next.Enabled = true;
    this.lb_back.Enabled = true;
    this.lb_one.Enabled = true;
    if (ps.IsFirstPage)
    {
        this.lb_one.Enabled = false;
        this.lb_up.Enabled = false;
    }
    if (ps.IsLastPage)
    {
        this.lb_next.Enabled = false;
        this.lb_back.Enabled = false;
    }
    //显示分页数量
    this.lblBackPage.Text = Convert.ToString(ps.PageCount);
    this.Repeater1.DataSource = ps;
    this.Repeater1.DataBind();
}

protected void lb_one_Click(object sender, EventArgs e)
{
    this.lblPage.Text = "1";
    this.Bind();
}
protected void lb_up_Click(object sender, EventArgs e)
{
    this.lblPage.Text = Convert.ToString(Convert.ToInt32(this.lblPage.Text) - 1);
    this.Bind();
}
protected void lb_next_Click(object sender, EventArgs e)
{
    this.lblPage.Text = Convert.ToString(Convert.ToInt32(this.lblPage.Text) + 1);
    this.Bind();
}
protected void lb_back_Click(object sender, EventArgs e)
{
    this.lblPage.Text = this.lblBackPage.Text;
    this.Bind();
}

}

.aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题页



<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0" width="95%" >
          <tr>
          <td width="90" align="center" >
            <%# DataBinder.Eval(Container.DataItem, "content")%>
            </td>
            </tr>
            </table>
</ItemTemplate>
</asp:Repeater>
<table cellpadding="0" cellspacing="0" >
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td align="center">
                    <asp:LinkButton ID="lb_one" runat="server" onclick="lb_one_Click">第一页</asp:LinkButton>

 上一页/asp:LinkButton ID="lb_next" runat="server" onclick="lb_next_Click">下一页/asp:LinkButton  ID="lb_back" runat="server" onclick="lb_back_Click">最后一页/asp:LinkButton

/asp:Label页 共 ID="lblBackPage" runat="server" Text="""">/asp:Label

 





请各位大神帮我看一下为什么没有效果、???

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!