无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。
private void btAdd_Click(object sender, System.EventArgs e)
{
DataTable dt = MusicClass.Songs.GetAllSongs();
DataRow dr = dt.NewRow();
dr[0] = "";
dr[1] = "";
dr[2] = "";
dr[3] = "";
dr[4] = "";
dr[5] = "";
dt.Rows.Add(dr);
this.dgSongs.DataSource = dt;
this.dgSongs.EditItemIndex = (dt.Rows.Count % this.dgSongs.PageSize )+1;
if (this.dgSongs.EditItemIndex == 0)
this.dgSongs.CurrentPageIndex = this.dgSongs.PageCount;
else
this.dgSongs.CurrentPageIndex = this.dgSongs.PageCount + 1;
this.dgSongs.DataBind();
}
------解决方案--------------------
this.dgSongs.CurrentPageIndex = this.dgSongs.PageCount + 1;
这个不对,CurrentPageIndex 最大是this.dgSongs.PageCount -1