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 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