我使用 gridview 来显示搜索结果。单击搜索按钮后,gridview 将显示第 1 页,但是当我单击第 2 页链接时,gridview 消失了,当我再次单击搜索按钮并显示第 2 页的内容时它又回来了。
这是我的代码
<asp:GridView ID="searchresult" runat="server" AutoGenerateColumns="true" AllowPaging="true" OnRowDataBound="searchresult_RowDataBound" OnPageIndexChanging="searchresult_PageIndexChanging"
HeaderStyle-BackColor="#f9e4d0"
HeaderStyle-Height="20px"
Font-Size="11px"
AlternatingRowStyle-BackColor="#cfdfef"
Width="800px" style="text-align:left">
</asp:GridView>
和后面的代码
protected void search_Click(object sender, EventArgs e)
{
List<someclass> totalResult = new List<someclass>();
..... //some code to generate the datasource
searchresult.DataSource = totalResult;
searchresult.AllowPaging = true;
searchresult.DataBind();
}
protected void searchresult_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void searchresult_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
searchresult.PageIndex = e.NewPageIndex;
DataBind();
}
我不知道为什么在我再次单击搜索按钮之前不会显示第 2 页。当我单击第 2 页链接时,该页面进行了回发,但未触发 RowDataBound 事件