数据分页(ViewState的用法)

         protected  System.Web.UI.WebControls.DataGrid DataGrid1;
        
private  DataTable dtPerson
        
{
            
set
            
{
                
this.ViewState["dt"]=value;
            }

            
get
            
{
                
return (DataTable)ViewState["dt"];
            }

        }

        
private   void  Page_Load( object  sender, System.EventArgs e)
        
{
            
if(!this.IsPostBack)
            
{
                dtPerson
=((ses)Session["user"]).execsearch("select * from Person");
                DataGrid1.DataSource
=dtPerson;
                DataGrid1.DataBind();
            }

        }

        
private   void  DataGrid1_PageIndexChanged( object  source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        
{
            DataGrid1.CurrentPageIndex
=e.NewPageIndex;
            DataGrid1.DataSource
=dtPerson;
            DataGrid1.DataBind();
        }


少量记录用此方法速度很快

试了下200多行20多个字段的表,几秒钟才刷新出来,内存也占了不少

你可能感兴趣的:(view)