| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1244 人关注过本帖
标题:点击上一页时经常出现“索引 -5 不是为负数,就是大于行数”,请高手帮忙! ...
只看楼主 加入收藏
小坏1015
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-5-30
结帖率:0
收藏
已结贴  问题点数:0 回复次数:3 
点击上一页时经常出现“索引 -5 不是为负数,就是大于行数”,请高手帮忙!!!
下面是Message.aspx
<table cellpadding="0" cellspacing="0">
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 750px" valign="top">
                <aspataList ID="nb_dl" runat="server">
                    <ItemTemplate>
                        <table cellpadding="0" cellspacing="0" style="width: 737px; border-right: #999999 1px solid; border-top: #999999 1px solid; border-left: #999999 1px solid; border-bottom: #999999 1px solid;">
                            <tr>
                                <td style="width: 550px; background-color: #CCCCCC;">
                                    <aspabel ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container,"dataitem.user_name") %>' Font-Bold="True" ForeColor="MidnightBlue"></aspabel></td>
                                <td style="width: 200px; background-color: #CCCCCC; text-align: left;">
                                    留言时间:<aspabel ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container,"dataitem.addtime") %>'></aspabel></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <aspabel ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container,"dataitem.book_content") %>'></asp:Label><br />
                                    <font color="#999999">——————————————————</font></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    回复:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container,"dataitem.book_reply") %>'></asp:Label></td>
                            </tr>
                        </table>
                    </ItemTemplate>
                </aspataList>
                <center>
    <table style="width:343px;">
                <tr>
                    <td colspan="2"><asp:Label ID="Label1" runat="server" Text="当前页:"></asp:Label>【<asp:Label ID="curPage" runat="server" Text="1"></asp:Label>】</td>
                    <td colspan="2"><asp:Label ID="Label2" runat="server" Text="共有"></asp:Label>【<asp:Label ID="totalPage" runat="server"  ></asp:Label>】<asp:Label ID="Label3" runat="server" Text="页" Width="1px"></asp:Label></td>
                    <td><asp:LinkButton ID="firstPage" runat="server" Text="首页"  Font-Underline="false"></asp:LinkButton></td>
                    <td><asp:LinkButton ID="frontPage" runat="server" Text="上一页"  Font-Underline="false"></asp:LinkButton></td>
                    <td><asp:LinkButton ID="nextPage" runat="server" Text="下一页"  Font-Underline="false"></asp:LinkButton></td>
                    <td><asp:LinkButton ID="lastPage" runat="server" Text="尾页"  Font-Underline="false"></asp:LinkButton></td>
                </tr>
            </table></center>
                </td>
            <td style="width: 100px">
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 750px"><hr color="#191970" />
            </td>
            <td style="width: 100px">
            </td>
        </tr>
        <tr>
            <td style="width: 100px">
            </td>
            <td style="width: 750px"></td>
            <td style="width: 100px">
            </td>
        </tr>
    </table>


下面是Message.aspx.cs
  protected void Page_Load(object sender, EventArgs e)
    {
        show_bind();
    }
protected void show_bind()
    {
        db da = new db();
        int currpage = Convert.ToInt32(this.curPage.Text);
        PagedDataSource pds = new PagedDataSource();
        string strcmd = "select * from netbook order by addtime desc";
        DataSet ds = da.DS1(strcmd, "book");
        pds.DataSource = ds.Tables["book"].DefaultView;
        pds.AllowPaging = true;//是否允许分页
        pds.PageSize = 5;//每页显示数量
        pds.CurrentPageIndex = currpage - 1;//获取当前页的页码
        this.firstPage.Enabled = true;
        this.frontPage.Enabled = true;
        this.nextPage.Enabled = true;
        this.lastPage.Enabled = true;
        if (currpage == 1)
        {
            //不显示首页和上一页
            this.firstPage.Enabled = false;
            this.frontPage.Enabled = false;
        }
        if (currpage == pds.PageCount)
        {
            //不显示尾页和下一页
            this.nextPage.Enabled = false;
            this.lastPage.Enabled = false;
        }
        //绑定datalist控件
        this.totalPage.Text = Convert.ToString(pds.PageCount);
        this.nb_dl.DataSource = pds;
        this.nb_dl.DataBind();
    }
    protected void firstPage_Click(object sender, EventArgs e)//第一页
    {
        this.curPage.Text = "1";//curPage.Text为当前页
        this.show_bind();
    }
    protected void frontPage_Click(object sender, EventArgs e)//上一页
    {
        this.curPage.Text = Convert.ToString(Convert.ToInt32(this.curPage.Text) - 1);
        this.show_bind();
    }
    protected void nextPage_Click(object sender, EventArgs e)//下一页
    {
        this.curPage.Text = Convert.ToString(Convert.ToInt32(this.curPage.Text) + 1);
        this.show_bind();
    }
    protected void lastPage_Click(object sender, EventArgs e)//尾页
    {
        this.curPage.Text = this.totalPage.Text;//totalPage.Text为总页数
        this.show_bind();
    }

下面的是db.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

/// <summary>
/// db 的摘要说明
/// </summary>
public class db
{
    private OleDbConnection oleconn;//声明一个OleDbConnection对象
    private OleDbCommand olecomm;//声明一个OleDbcommand对象
    private OleDbDataAdapter oleda;//声明一个OleDbDataAdapater对象
        public db()
        {
        oleconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data/zsj_table.mdb"));
        oleconn.Open();
    }
    public bool exceole(string olecmd)//用该方法来执行sql语句
    {
        olecomm = new OleDbCommand(olecmd, oleconn);
        try
        {
            olecomm.ExecuteNonQuery();
            return true;
        }
        catch (Exception e)
        {
            throw (new Exception(e.Message));
            return false;
        }
        finally
        {
            oleconn.Close();
        }
    }


    //返回一个dataset类型数据
    public DataSet DS(string strcom)
    {
        try
        {
            olecomm = new OleDbCommand(strcom, oleconn);
            oleda = new OleDbDataAdapter();
            oleda.SelectCommand = olecomm;
            DataSet ds = new DataSet();
            oleda.Fill(ds);
            return ds;
        }
        finally
        {
            oleconn.Close();
        }
    }


    public DataSet DS1(string strcom, string tablename)
    {
        try
        {
            OleDbDataAdapter oleda = new OleDbDataAdapter(strcom, oleconn);
            DataSet ds = new DataSet();
            oleda.Fill(ds, tablename);
            return ds;
        }
        finally
        {
            oleconn.Close();
        }
    }


    //返回一个OleDbdatareader类型数据

    public OleDbDataReader oledr(string strcom)
    {
        olecomm = new OleDbCommand(strcom, oleconn);
        OleDbDataReader sdr = olecomm.ExecuteReader();
        return sdr;
        oleconn.Close();
    }
}


以上就是全部的代码,可是我实在是找不出来为什么老是出现“索引 -5 不是为负数,就是大于行数”,还有当我点击下一页时,它只能跳到第二页,根本就不能跳到第三页,只有点击尾页时,它才跳到第三页,然后只要一点击上一页,就会出现如帖子标题的问题了,很郁闷的! 请各位高手帮忙解决下,谢谢了先!!!

搜索更多相关主题的帖子: style 
2011-06-08 15:02
小坏1015
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-5-30
收藏
得分:0 
高手们能帮忙的就帮帮忙吧,谢谢你们了!

破碎机|http://www.
2011-06-08 15:12
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:10 
把报错页面的所有信息都发上来,看代码没发现哪里有问题

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2011-06-08 15:22
tw920217
Rank: 4
来 自:湖南
等 级:业余侠客
帖 子:64
专家分:217
注 册:2011-6-2
收藏
得分:10 
    你把咱都当VS来帮你找错误呢. 你能把错误贴出来么

Best   Regards
公司分機:886-03-250-8800-2156
手機:15818580357  聯系地址:深圳
2011-06-08 17:06
快速回复:点击上一页时经常出现“索引 -5 不是为负数,就是大于行数”,请高手帮 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022436 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved