分页在 Gridview 中无法正常工作

Paging is Not working Properly in Gridview

当我使用两个文本框搜索数据并按下按钮时,数据被填充到 Gridview 中。我设置 Allow Paging =True。当我尝试在 Gridview 中从第一页移动到第二页时,gridview 会消失。 我的代码

<asp:GridView runat="server" ID="Gv1" EmptyDataText="No Recorde Found"             
         AllowPaging="true" AutoGenerateColumns="false" PageSize="10"       
         OnPageIndexChanging="Gv1_PageIndexChanging" 
         OnRowCommand="Gv1_RowCommand" >

--

protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   Gv1.PageIndex = e.NewPageIndex;
   LoadGrid();
}

这样试试

  protected void btnSearch_Click(object sender, EventArgs e) 
  {
     if (ddl1.SelectedIndex > 0 )
     {
          x = ddl1.SelectedItem.ToString();
      } 

      if (ddl2.SelectedIndex > 0) {
          y = ddlProgram.ddl2.ToString(); 
      } 

      BindGrid();
 }

private void BindGrid() {
 if (ViewState["mySearchedData"] != null) {
    gv.DataSource = ViewState["mySearchedData"];
    gv.DataBind();
 }
 else 
 {
    gv.DataSource = wcfobj.GetData(x,y);
    gv.DataBind();
    ViewState["mySearchedData"]= wcfobj.GetData(x,y);
  }
 }