搜索的
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          初始化的时候这边 这样调用一次,要初始化数            process.initDDl4ItemType(ddlItemType_query);
            initDDl4Year_JobNumUse(ref StrDateStart,ref StrDateStart_m,ref StrDateEnd,ref StrDateEnd_m);  //初始化年月            calendar1.Text = StrDateStart;
            calendar1_m.Text = "0" + common.cstSetStartAndEndTime + ":00";            calendar2.Text = StrDateEnd;
            calendar2_m.Text = "0" + common.cstSetStartAndEndTime + ":00";            StrItemSecondName = txtItemSecondName.Text.ToString();
            StrItemTypeID = ddlItemType_query.SelectedValue.ToString();
            StrSteelCode = txtSteelCode.Text.ToString();
            this.dataBind_detail(StrDateStart, StrDateEnd, StrDateStart_m, StrDateEnd_m, StrItemSecondName, StrItemTypeID, StrSteelCode);
        }
    }//这边使用页内变量    public string StrDateStart = "";
    public string StrDateEnd = "";
    public string StrDateStart_m = "";
    public string StrDateEnd_m = "";
    public string StrItemCode = "";
    public string StrItemSecondName = "";
    public string StrItemTypeID  = "";
    public string StrddlDayOrNight = "";
    public string StrSteelCode = "";    public DataTable golbalTable;    /// <summary>
    /// 库存信息,数据绑定
    /// </summary>
    private void dataBind_detail(string StrDateStart, string StrDateEnd, string StrDateStart_m, string StrDateEnd_m, string StrItemSecondName, string StrItemTypeID, string StrSteelCode)
    {
        string strWhere = "";
        string strWhereDate = "";        string strWhereDatePZ = "";
        string strWhereDateRK = "";
        string strWhereDateSG = "";
        string strWhereDateXG = "";
        string strWhereDateZZ = "";        try
        {
            string strSql = "select * FROM table1 ";
                           
            int myRdrCount = 0;
            myRdrCount = SqlHelper.getReadCount(SqlHelper.ConnectionStringLocalTransaction, strSql, null);
            AspNetPager2.RecordCount = myRdrCount;            AspNetPager2.AlwaysShow = true;
            AspNetPager2.PageSize = 15;            SqlDataAdapter oda = new SqlDataAdapter(strSql, SqlHelper.ConnectionStringLocalTransaction);
            DataSet ds = new DataSet();
            oda.Fill(ds, AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1), AspNetPager2.PageSize, "dbTable");
            GridViewDetail.DataSource = ds.Tables[0];
            GridViewDetail.DataBind();        }
        catch (Exception err)
        {
            Response.Write(err.Message);
        }
        finally
        { 
            
        }    }
 //分页调用,用的是AspNetPager 组件哦。这样对变量赋值。    /// <summary>
    /// 分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        StrDateStart = calendar1.Text.ToString();
        StrDateEnd = calendar2.Text.ToString();
        StrDateStart_m = calendar1_m.Text.ToString();
        StrDateEnd_m = calendar2_m.Text.ToString();
        StrItemSecondName = txtItemSecondName.Text.ToString();
        StrItemTypeID = ddlItemType_query.SelectedValue.ToString();
        StrSteelCode = txtSteelCode.Text.ToString();        this.dataBind_detail(StrDateStart, StrDateEnd, StrDateStart_m, StrDateEnd_m, StrItemSecondName, StrItemTypeID, StrSteelCode);
    }
//查询这边 这样调用一次,。像我这样再次对变量赋值,    protected void btn_Query_Click(object sender, EventArgs e)
    {
        StrDateStart = Request.Form["calendar1"].Trim();
        StrDateEnd = Request.Form["calendar2"].Trim();
        StrDateStart_m = Request.Form["calendar1_m"].Trim();
        StrDateEnd_m = Request.Form["calendar2_m"].Trim();        calendar1.Text = StrDateStart;
        calendar2.Text = StrDateEnd;
        calendar1_m.Text = StrDateStart_m;
        calendar2_m.Text = StrDateEnd_m;        StrItemSecondName = txtItemSecondName.Text.ToString();
        StrItemTypeID = ddlItemType_query.SelectedValue.ToString();
        StrSteelCode = txtSteelCode.Text.ToString();        this.dataBind_detail(StrDateStart, StrDateEnd, StrDateStart_m, StrDateEnd_m, StrItemSecondName, StrItemTypeID, StrSteelCode);
    }
}-------------------------
对于变量
    public string StrDateStart = "";
    public string StrDateEnd = "";
    public string StrDateStart_m = "";
    public string StrDateEnd_m = "";
    public string StrItemCode = "";
    public string StrItemSecondName = "";
    public string StrItemTypeID  = "";
    public string StrddlDayOrNight = "";
    public string StrSteelCode = "";我多次赋值用在 分页 和 查询 事件中。非常麻烦。
请问是不是用
ViewState[] 的方法来对上面的变量赋值可以减少变量多次赋值现在我想问的是ViewState[] 会占内存吗?在B/S项目中用来代替 这些变量合适吗?
性能怎么样?谢谢

解决方案 »

  1.   


    这个是没错。但是我搜索完后,剩下的数据还是要分页的。
    我想问的是变量多次赋值这样写太麻烦了。
    你们都是用 ViewState[] 这边方法在页面上给变量赋值吗?
    只要写一次即可吗?
      

  2.   

    我多次赋值用在 分页 和 查询 事件中。非常麻烦。
    请问是不是用
    ViewState[] 的方法来对上面的变量赋值可以减少变量多次赋值现在我想问的是
    ViewState[StrDateStart ] 
    ViewState[StrDateEnd] 
    ViewState[StrDateStart_m] 
    ViewState[StrDateEnd_m] 
    ViewState[StrItemCode] 会占内存吗?在B/S项目中用来代替 这些变量合适吗?
    性能怎么样?谢谢。
      

  3.   

    ViewState 会占内存,它是隐藏的控件,数量太大,肯定会影响性能。
      

  4.   

    ?a=fdsfsdf&b=bbb............
    viewstate
      

  5.   

    不到万不得已 最好不要用ViewState最好..还有 你完全不用这样传值的.你把绑定数据的代码提取出来成一个独立方法. 然后AspNetPager2_PageChanged事件换成 AspNetPager2_PageChanging事件 改变页数 直接重新绑定就行了 AspNetPager2.currentIndex=e.newIndex;
    //绑定数据的方法
    BindData()