君子兰 2007-11-23 09:33
页面无限跳转间如何保存页面状态 (3)
在页面上的使用,定义好了以上这些之后,在页面中该怎样用呢?
首先,在List页面中实现IPageInfo接口:
public class RoleList : System.Web.UI.Page,IPageInfo
然后针对每一个DataGrid实例化一个DataInfo对象:
protected DataInfo dataInfo = new DataInfo("Role");
接着写一些处理DataGrid状态的代码,我是使用的属性:
#region 数据网格状态信息
** System.Collections.Hashtable SearchParams
{
get
{
if (ViewState["SearchParams"] != null)
{
return (Hashtable)ViewState["SearchParams"];
}
else
return null;
}
set
{
ViewState["SearchParams"] = value;
}
}
** System.Collections.Hashtable OtherDataParams
{
get
{
if (ViewState["OtherDataParams"] != null)
{
return (Hashtable)ViewState["OtherDataParams"];
}
else
return null;
}
set
{
ViewState["OtherDataParams"] = value;
}
}
** int CurrentPage
{
get
{
return MyDataGrid.CurrentPageIndex;
}
set
{
MyDataGrid.CurrentPageIndex = value;
MyDataGrid.DataBind();
navigateRole.CurrentPage = MyDataGrid.CurrentPageIndex 1;
navigateRole.TotalPages = MyDataGrid.PageCount;
}
}
** string SortExpression
{
get
{
return dsSystem.Role.DefaultView.Sort;
}
set
{
dsSystem.Role.DefaultView.Sort = value;
MyDataGrid.DataBind();
navigateRole.TotalPages = MyDataGrid.PageCount;
}
}
** string ItemID
{
get
{
if (MyDataGrid.SelectedIndex >= 0)
{
return MyDataGrid.DataKeys[MyDataGrid.SelectedIndex].ToString();
}
else
return null;
}
set
{
int pageIndex = MyDataGrid.CurrentPageIndex;
bool find = false;
for( int j = 0; j < MyDataGrid.PageCount