AspNetPager查詢分頁問題(點擊頁碼,不再是查詢後的資料集)viewstate解決

來源:互聯網
上載者:User

標籤:blog   color   os   io   ar   for   資料   art   問題   

public string SQL = "select * from Memorandum";      protected void Page_Load(object sender, EventArgs e)      {          if (!IsPostBack)          {              ViewState["SQL"] = SQL;              BindData();          }          if (Request.QueryString["MId"] != null)          {              Delete(int.Parse(Request.QueryString["MId"].ToString()));          }      }       protected void AspNetPager1_PageChanged(object sender, EventArgs e)      {          BindData();      }            void BindData()      {          PagedDataSource pds = new PagedDataSource();          IList<MemorandumInfo> Infos = new DAL.Memorandum().GetAllMemorandumsBySQL(ViewState["SQL"].ToString());           pds.DataSource = Infos;          pds.AllowPaging = true;          pds.PageSize = 10;//取控制項的分頁大小          pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;//顯示當前頁          //設定控制項          this.AspNetPager1.RecordCount = Infos.Count;//記錄總數          this.AspNetPager1.PageSize = 10;          Repeater1.DataSource = pds;          Repeater1.DataBind();      }      void Delete(int MId)      {          new Memorandum().DeleteMemorandum(MId);          Response.Write("<script>alert(‘成功刪除該條備忘資訊‘);location=‘?‘;</script>");      }      /// <summary>      /// 查詢      /// </summary>      /// <param name="sender"></param>      /// <param name="e"></param>       protected void Button1_Click(object sender, EventArgs e)      {          if (DropDownList1.SelectedValue == "0")          {              ViewState["SQL"] = "select * from Memorandum";              BindData();          }          else          {              ViewState["SQL"] = "SELECT   MId, MemoTitle, MemoContent, MemoStartTime, MemoEndTime FROM  Memorandum WHERE (MemoEndTime - NOW() <=7)";              BindData();          }      }  }

ViewState 用來跟蹤和儲存控制項的狀態資訊。否則這些資訊可能會丟失,原因可能是這些值不隨著 form 回傳,或者根本就不在 page 的 html 中。
ViewState 中儲存著代碼中改變的控制項屬性,通過代碼綁定到控制項的任何資料,以及由使用者操作觸發,回傳的任何更改。
ViewState 還提供了一個狀態包(StateBag), 這是一個特殊的集合或字典(collection or dictionary), 可以用來儲存,通過一個 key 來恢複任意的對象或者值。

賦值:ViewState[key] = value;

取值:value = ViewState[key];

(轉)AspNetPager查詢分頁問題(點擊頁碼,不再是查詢後的資料集)viewstate解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.