Aspnetpager Query paging problem (click Page number, no longer the data set after query) viewstate resolve

Source: Internet
Author: User

publicstringSQL = "select * from Memorandum";      protectedvoidPage_Load(objectsender, EventArgs e)      {          if(!IsPostBack)          {              ViewState["SQL"] = SQL;              BindData();          }          if(Request.QueryString["MId"] != null)          {              Delete(int.Parse(Request.QueryString["MId"].ToString()));          }      }      protectedvoidAspNetPager1_PageChanged(object sender, EventArgs e)      {          BindData();      }           voidBindData()      {          PagedDataSource pds = newPagedDataSource();          IList<MemorandumInfo> Infos = newDAL.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();      }      voidDelete(intMId)      {          newMemorandum().DeleteMemorandum(MId);          Response.Write("<script>alert(‘成功删除该条备忘信息‘);location=‘?‘;</script>");      }      /// <summary>      /// 查询      /// </summary>      /// <param name="sender"></param>      /// <param name="e"></param>      protectedvoidButton1_Click(objectsender, 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 is used to track and save state information for a control. Otherwise, this information may be lost, either because the values are not being sent back with the form or are not in the HTML of the page at all.
ViewState holds the changed control properties in the code, any data that is bound to the control by code, and any changes that are triggered by the user action and postback.
ViewState also provides a status pack (StateBag), which is a special set or dictionary (collection or dictionary) that can be used to save and restore arbitrary objects or values through a key.

Assignment: Viewstate[key] = value;

Value: value = Viewstate[key];

(GO) Aspnetpager Query paging problem (click Page number, no longer the data set after query) viewstate resolve

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.