Put a gridView in an UpdatePanel. When you click the page, you need to click twice to display the correct content. At the beginning, I thought it was an UpdatePanel problem, I found some conclusions on the Internet but failed to solve the problem. Using fiddler to monitor http information, you can see that the information passed during the first click is correct, for example:
The correct page number can be passed, but the returned page data is incorrect. Therefore, it should be a code issue. Because table data is read through the custom process, you must obtain the data again each time the page is submitted. The Gridview cannot pass its data source through the viewstate attribute.
The code for getting data is as follows:
Private void GetData ()
{
Localhost. QueryCondition condition = null;
If (txtSearchValue. Value! = "") // Empty search all
{
Condition = new localhost. QueryCondition
{
FieldName = slctSearchFields. Value,
FieldOper = slctCondition. Value,
FieldValue = txtSearchValue. Value
};
}
Localhost. CominfoTemplateService1 service = new localhost. CominfoTemplateService1 ();
GridInfo. DataSource = service. SearchComsByUserName (Context. User. Identity. Name, condition );
GridInfo. DataBind ();
}
The paging code in the table is like this.
protected void gridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GetData();
gridInfo.PageIndex = e.NewPageIndex;
}
The tracking code finds that after databind of the grid, the rowdata_bind event will be triggered and the data will be filled. At this time, the page number of the table has not changed, and the order of calling the two statements is:
gridInfo.PageIndex = e.NewPageIndex;
GetData();
Solve the problem.