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.
任何人都可以帮忙吗?
答案 0 :(得分:0)
看起来invList.DataBind正在设置的绑定是指诸如dv之类的视图。这是猜测,因为它会在您的代码中的其他位置。
对于要在简单控件中显示的多行表中的数据,绑定需要知道要使用哪一行,此错误表示确定行正在返回的任何内容"索引4" (第5行...索引从0开始),表中有4行或更少的行。
检查行导航,尤其是在更改基础表的内容之后,确保其当前行设置为有效数字。