日期:2014-05-17  浏览次数:20523 次

asp.net翻页代码无效,,,急急
我用的是vs2008,数据库是sql 2005,c#

更多后台代码
using BLL;

public partial class gengduo : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
   
  if (!IsPostBack)
  {

  //bd();//这句话加上就提示:无法找到表 0。
  }

  }
  public void bd()
  {

  DAL.DataBase d = new DAL.DataBase();
  DataSet ds = new DataSet();
  //d.runSQL("select * from news where newsID=" + Request["id"].ToString() + "order by newsID DESC", ref ds);


  PagedDataSource p = new PagedDataSource();
  p.DataSource = ds.Tables[0].DefaultView;
  p.AllowPaging = true;
  p.PageSize = 2;


  int cp = 0;
  if (Request["page"] != null)
  {
  cp = Convert.ToInt32(Request["page"]);


  }

  p.CurrentPageIndex = cp;
  if (!p.IsFirstPage)
  {

  HyperLink1.NavigateUrl = "?id=" + Request["id"].ToString() + "&page=" + (cp - 1);


  }
  if (!p.IsLastPage)
  {

  HyperLink2.NavigateUrl = "?id=" + Request["id"].ToString() + "&page=" + (cp + 1);

  }

  HyperLink3.NavigateUrl = "?id=" + Request["id"].ToString() + "&page=" + 0;
  HyperLink4.NavigateUrl = "?id=" + Request["id"].ToString() + "&page=" + (p.PageCount - 1);
  showPage.Text = "第" + (p.CurrentPageIndex + 1) + "页共" + p.PageCount + "页";

  DataList1.DataSource = p;
  DataList1.DataBind();
  d.close();

前台代码
  <asp:Literal ID="showPage" runat="server"></asp:Literal>
  <asp:HyperLink ID="HyperLink1" runat="server">上一页</asp:HyperLink>
  <asp:HyperLink ID="HyperLink2" runat="server">下一页</asp:HyperLink>
  <asp:HyperLink ID="HyperLink3" runat="server">首页</asp:HyperLink>
  <asp:HyperLink ID="HyperLink4" runat="server">尾页</asp:HyperLink>

------解决方案--------------------
C# code

DAL.DataBase d = new DAL.DataBase();
  DataSet ds = new DataSet();
  //d.runSQL("select * from news where newsID=" + Request["id"].ToString() [color=#FF0000]+ "order (order前面加个空格)[/color]by newsID DESC", ref ds);[color=#FF0000]这里注释了???[/color]


  PagedDataSource p = new PagedDataSource();
  p.DataSource = ds.Tables[0].DefaultView;
  p.AllowPaging = true;
  p.PageSize = 2;

------解决方案--------------------
C# code

DAL.DataBase d = new DAL.DataBase();
  DataSet ds = new DataSet();
  d.runSQL("select * from news where newsID=" + Request["id"].ToString() [color=#FF0000]+ "order (order前面加个空格)[/color]by newsID DESC", ref ds);[color=#FF0000]这里注释了???[/color]


  PagedDataSource p = new PagedDataSource();
  p.DataSource = ds.Tables[0].DefaultView;
  p.AllowPaging = true;
  p.PageSize = 2;

------解决方案--------------------
用个分页空间不是很好吗
------解决方案--------------------

看错问题了,我以为“无法找到表 0。”呢...