帮忙看看我的datalist分页出错在哪了吧,卡在这儿两天了.
前几天做了个datalist分页运行良好,同在却报起错来.
错误:
索引-4不是为负数,就是大于行数.
代码如下:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session.Add( "test1 ", 0);
fenye();
}
}
protected void fenye()
{
SqlConnection con = DB.createConnection();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand( "select * from DetailsView ", con);
DataSet ds = new DataSet();
sda.Fill(ds, "emp ");
System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables[ "emp "].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 4;
this.LabelNum.Text= Convert.ToString(Convert.ToInt32(Session[ "test1 "])+1);//labelNum显示页码.
ps.CurrentPageIndex = Convert.ToInt32(Session[ "test1 "]);
this.Btnleft.Enabled = true;
this.BtnRight.Enabled = true;
if (Convert.ToInt32(Session[ "test1 "]) == 0)
{
this.Btnleft.Enabled = false;//Btnleft为控制向左翻页
}
if (Convert.ToInt32(Session[ "test1 "]) == ps.PageCount - 1)
{
this.BtnRight.Enabled = false;//Btnright为控制向右翻页
}
this.DataListALL.DataSource = ps;
&nb