如题:如何生public DataSet,我想在一页面Load时生成一DataSet ,当前页面的其它方法可以引用它。
 public partial class ASPX_test : System.Web.UI.Page
    {
        private int i = 0;
        public DataSet ds;
             ...
             ...
             ...以上是我的代码报错。应如何做呢?TKS

解决方案 »

  1.   

    转载:
    WEB程序不太一样,要记住,B/S程序是无状态的,也就是说,当你提交按钮的时候,上一次页面运行的时候所有的一切都被清空了,你必须重新来. 
    服务器控件还能保留以前的状态是因为系统提供了VIEWSTATE,供系统在回发之后从中取出控件的值再次自动加载,而你自己定义的数据,已经全没了.
      

  2.   

    写到page_load上面
    public DataSet ds=null;
      

  3.   

    楼上的朋友,是写在page_load的上面的,全部页面代码如下:using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;     public partial class ASPX_test : System.Web.UI.Page
        {
            myClass myFun = new myClass();        private int i = 0;
            public DataSet ds=null;
            
                protected void Page_Load(object sender, EventArgs e)
            {                DataSet ds=new DataSet();
                    ds= myFun.GetDataSet("select   a,b,c,d   from   Goods where 1=1");
              
                this._CursorSkip();        }        protected void _CursorSkip()
            {                     this.TextBox2.Text = ds.Tables[0].Rows[i][0].ToString();
                this.TextBox3.Text = ds.Tables[0].Rows[i][1].ToString();
                this.TextBox4.Text = ds.Tables[0].Rows[i][2].ToString();
                this.TextBox5.Text = ds.Tables[0].Rows[i][3].ToString();        }        protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
            {        }
            protected void Button3_Click(object sender, EventArgs e)
            {
                this.MultiView1.ActiveViewIndex = 2 - 1;        }
            protected void Button2_Click(object sender, EventArgs e)
            {
                this.MultiView1.ActiveViewIndex = 3 - 1;        }
            protected void Button4_Click(object sender, EventArgs e)
            {
                this.MultiView1.ActiveViewIndex = 1 - 1;        }
            protected void Button8_Click(object sender, EventArgs e)
            {
                i = ds.Tables[0].Rows.Count;
            }
            protected void Button12_Click(object sender, EventArgs e)
            {
                if (i < ds.Tables[0].Rows.Count)
                {
                    i += 1;
                }
                this._CursorSkip();        }
            protected void Button11_Click(object sender, EventArgs e)
            {
                if (i > 0)
                {
                    i -= 1;
                }
                this._CursorSkip();
            }
            protected void Button6_Click(object sender, EventArgs e)
            {
                i = 0;
                this._CursorSkip();
            }
    }