后台代码:  protected void btnHistory_Click(object sender, EventArgs e)
    {
        HouseRentBusiness hrb=new HouseRentBusiness();
        if (Request.QueryString["HouseID"] != null)
        {
            DataTable dt = new DataTable();
            string message = hrb.selectHistoryDetail(Request.QueryString["HouseID"].ToString(),ref dt);
            if (message == "")
            {
                GridView gvHistory = new GridView();
                gvHistory.AutoGenerateColumns = false;
                gvHistory.Width = Unit.Parse("100%");
                gvHistory.AllowPaging = true;
                gvHistory.PageSize = 2;                BoundField bfHouseID = new BoundField(); bfHouseID.HeaderText = "单位编号"; bfHouseID.DataField = "HouseID";               
                gvHistory.Columns.Add(bfHouseID);                gvHistory.DataSource = dt;
                gvHistory.DataBind();
                
                divGvHistory.Controls.Add(gvHistory);
            }
}
    }运行到gvHistory.DataBind();这句就报错,未将对象引用设置到对象实例。
如果  将              gvHistory.AllowPaging = true; gvHistory.PageSize = 2; 去掉,就不会报错。
或者 gvHistory.AllowPaging = true; gvHistory.PageSize = 2; 单数据源中的数据量小于gvHistory.PageSize 也不会报错请问这是什么原因?