日期:2013-11-22  浏览次数:20491 次

在页面上的使用,定义好了以上这些之后,在页面中该怎样用呢?
首先,在List页面中实现IPageInfo接口:
public class RoleList : System.Web.UI.Page,IPageInfo
然后针对每一个DataGrid实例化一个DataInfo对象:
protected DataInfo dataInfo = new DataInfo("Role");
接着写一些处理DataGrid状态的代码,我是使用的属性:
#region 数据网格状态信息
private System.Collections.Hashtable SearchParams
{
get
{
if (ViewState["SearchParams"] != null)
{
return (Hashtable)ViewState["SearchParams"];
}
else
return null;
}
set
{
ViewState["SearchParams"] = value;
}
}

private System.Collections.Hashtable OtherDataParams
{
get
{
if (ViewState["OtherDataParams"] != null)
{
return (Hashtable)ViewState["OtherDataParams"];
}
else
return null;
}
set
{
ViewState["OtherDataParams"] = value;
}
}

private int CurrentPage
{
get
{
return MyDataGrid.CurrentPageIndex;
}
set
{
MyDataGrid.CurrentPageIndex = value;
MyDataGrid.DataBind();
navigateRole.CurrentPage = MyDataGrid.CurrentPageIndex + 1;
navigateRole.TotalPages = MyDataGrid.PageCount;
}
}

private string SortExpression
{
get
{
return dsSystem.Role.DefaultView.Sort;
}
set
{
dsSystem.Role.DefaultView.Sort = value;
MyDataGrid.DataBind();
navigateRole.TotalPages = MyDataGrid.PageCount;
}
}

private 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 && find == false; j++)
{
MyDataGrid.CurrentPageIndex = j;
MyDataGrid.DataBind();
for(int i = 0; i < MyDataGrid.Items.Count; i++)
{
if (MyDataGrid.DataKeys[i].ToString() == value)
{
find = true;
break;
}
}
}
if (find == false)
{
MyDataGrid.CurrentPageIndex = pageIndex;
MyDataGrid.DataBind();
}
navigateRole.CurrentPage = MyDataGrid.CurrentPageIndex + 1;
navigateRole.TotalPages = MyDataGrid.PageCount;
}
}
#endregion

在PageLoad