点击button1之后,页面重新Load,this.dataSet1的值被清空了

解决方案 »

  1.   

    在Button2_Click代碼最前面加上
    Button1_Click(sender,e);
      

  2.   

    建议如下修改
    button1中,最后添加一句
    da.Fill(dataSet1,"employees");
    之后添加:
    this.viewState["db"] = this.dataSet1;button2中
    this.DataGrid1.DataSource=dataSet1.Tables["employees"].DefaultView;
    ---》
    this.DataGrid1.DataSource=((DataSet)this.viewstate["db"]).Tables["employees"].DefaultView;
      

  3.   

    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected Static DataSet dataSet1;
      

  4.   

    你需要理解页面执行顺序,你的程序:
    private void InitializeComponent()
    {    
    this.dataSet1 = new System.Data.DataSet();当点击按钮后,页面回发,但它还是会建立页实例,同时又建立了DataSet,所以并没有到对象的引用