我的gridview控件有问题。我创建了一个带有下拉列表、检索按钮和网格视图控件的表单。我从下拉列表中选择一个值,单击按钮,网格视图将在两页中填充数据。当我点击第二页时,数据就不见了。我必须再次按下检索按钮,然后第二页才能正确显示。我使用了PageIndexChanging,但它没有任何变化。有什么想法吗?
确保他的数据源在回发时没有重置。
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GridView1.DataSource = new DirectoryInfo("C:\windows").GetFiles();
this.GridView1.PageSize = 3;
this.GridView1.AllowPaging = true;
this.GridView1.DataBind();
}
}
将PageIndexChanging方法实现到网格。。。例如。
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
}