2
DataView dv = ds.Tables["Unit"].DefaultView;
dv.RowFilter = SqlWhere;
dv.Sort = SortList.SelectedValue.ToString();
PagedDataSource page = new PagedDataSource();
page.DataSource = dv;
page.AllowPaging = true;
page.PageSize = Int32.Parse(ResultList.SelectedValue);
page.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " +
                                                        page.PageCount.ToString();
// Disable Prev or Next buttons if necessary
cmdPrev.Enabled = !page.IsFirstPage;
cmdNext.Enabled = !page.IsLastPage;
invList.DataSource = page;
invList.DataBind();
public int CurrentPage
{
    get
    {
        // look for current page in ViewState
        object o = this.ViewState["_CurrentPage"];
        if (o == null)
            return 0; // default page index of 0
        else
            return (int)o;
    }

    set
    {
        this.ViewState["_CurrentPage"] = value;
    }
}

但它现在显示这样的错误invList.DataBind();

Index 4 is either negative or above rows count.

描述

 An unhandled exception occurred during the execution of the current web request. 
 Please review the stack trace for more information about the error and where it 
 originated in the code. 

异常详情

System.IndexOutOfRangeException: Index 1 is either negative or above rows count.

谁能帮忙?

4

1 回答 1

0

看起来 invList.DataBind 正在设置的绑定指的是诸如 dv 之类的视图。这是一个猜测,因为它会在您的代码中的其他地方。

对于要在简单控件中显示的多行表中的数据,绑定需要知道要使用哪一行,此错误表示确定行的任何内容都返回“索引 4”(第 5 行...索引开始于0) 表中有 4 行或更少的行。

检查您的行导航,尤其是在更改基础表的内容后,确保其当前行设置为有效数字。

于 2013-11-29T10:38:15.287 回答