指标1为负或以上行数 [英] Index 1 is either negative or above rows count

查看:188
本文介绍了指标1为负或以上行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

谁能帮助?

推荐答案

它看起来像绑定其invList.DataBind是建立是指一个视图如DV。这是因为它会在你的code别处猜测。

It looks like bindings which invList.DataBind is setting up are referring to a view such as dv. This is a guess as it'll be elsewhere in your code.

有关在一个简单的控制显示从多行表数据,结合需要知道使用哪一行,这个错误是说,无论是确定该行正在返回指数4(5排...指数从0开始),那里有表中的4个或更少的行。

For data from a multi row table to be shown in a simple control, the binding needs to know which row to use, this error is saying that whatever is determining the row is returning "Index 4" (row 5... index starts at 0) where there are 4 or fewer rows in the table.

检查行导航,尤其是改变底层表的内容后,要确保它的当前行设置为一个有效的数字。

Check your row navigation, especially after changing the contents of the underlying table, make sure its current row is set to a valid number.

这篇关于指标1为负或以上行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆