public partial class Location_BJ_Location : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
this.GridView1.DataSource = this.Dbind();
this.GridView1.DataBind();
}
}
public DataSet Dbind(){
string strLocation = "北京";
DataSet ds = new DataSet();
DBAccess db = new DBAccess();
ds = db.GetLLData(strLocation);
return ds;
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataSource = this.Dbind();
this.GridView1.DataBind();
}
}
这个用到了GriView的自动分页功能,但是运行以后出现如题的问题。网上查找了许多,不见解,遂自己尝试了解决一下问题。修改Page_Load()函数里面,函数如下
protected void Page_Load(object sender, EventArgs e)
{
this.GridView1.DataSource = this.Dbind();
this.GridView1.DataBind();
}
取消掉了if(!Page.IsPostBack){} ,再次运行,分页显示正常。
个人觉得当运行Page_Load函数时,网页第一次加载成功以后,点击"2,3,4,...."分页时,属于加载过的加上 Page.IsPostBack函数不会再重新给GridView重新绑定数据源,所以还会出现空白页(个人意见而已,希望大家批评改正)。