How to save page status between infinite jumps on a page (3)

Source: Internet
Author: User
Tags sort tostring
The use of the page on the page, defined above these, in the page how to use it?
First, implement the Ipageinfo interface in the list page:
public class Rolelist:system.web.ui.page,ipageinfo
Then instantiate a Datainfo object for each datagrid:
protected Datainfo Datainfo = new Datainfo ("role");
Then write some code that handles the DataGrid state, the properties I use:
#region Data grid state information
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

Take out the data from the previous page in the pageload and process it, note that the previous page comes with the Server.Transfer method:
Ipageinfo pageInfo = null;
Remove information from the previous page and save information about the status of the data grid
Try
{
PageInfo = (ipageinfo) Context.Handler;
}
Catch {}
if (pageInfo!= null)
{
if (pageinfo.otherparams!= null)
Otherparams = Pageinfo.otherparams;
if (Pageinfo.datainfos!= null)
{
Save all DataGrid Information
Datainfos = Pageinfo.datainfos;
Remove information from the current DataGrid
if (Pageinfo.datainfos[datainfo.dataname]!= null)
{
Datainfo = Pageinfo.datainfos[datainfo.dataname];
}
}
}
Take the data out and then naturally is processed, I set the values of the previous attributes, in fact there are many ways, here is not detailed.
Ipageinfo implementation, where the Datainfos property is updated to update the Datainfo information for each DataGrid on the page to reflect the most recent changes:
public string pagename
{
Get
{
return "Rolelist";
}
}

Public Hashtable Otherparams
{
Get
{
if (viewstate["otherparams"]!= null)
{
Return (Hashtable) viewstate["Otherparams"];
}
Else
return null;
}
Set
{
viewstate["Otherparams"] = value;
}
}

Public Datainfolist Datainfos
{
Get
{
Update Data grid status information
Datainfolist datainfolist;
if (viewstate["Datainfos"]!= null)
Datainfolist = (datainfolist) viewstate["Datainfos"];
Else
Datainfolist = new Datainfolist ();
Datainfo.currentpage = CurrentPage;
Datainfo.itemid = ItemID;
Datainfo.otherparams = Otherdataparams;
Datainfo.searchparams = Searchparams;
Datainfo.sortexpression = SortExpression;
Datainfolist[datainfo.dataname] = Datainfo;
return datainfolist;
}
Set
{
viewstate["Datainfos"] = value;
}
}

Jump to another page (such as a detail page):
Server.Transfer ("roledetail.aspx");

For detail pages, it is simpler because there is basically no datinfo update problem, which is intended to be deleted and added when the Itemid needs to be modified:
The interface is implemented first:
public class Roledetail:system.web.ui.page,ipageinfo
Then define two variables, one to save the data from the previous page, and one to define the current category of data, that is, which datainfo instance to operate on:
protected Ipageinfo PageInfo;
protected string dataname = "role";

Pageload Remove the front page data and process the current item data:
Try
{
PageInfo = (ipageinfo) Context.Handler;
}
Catch
{
}
Remove the ID of the current item
if (pageInfo!= null && pageinfo.datainfos!= null)
{
Datainfos = Pageinfo.datainfos;
}
Take detailed data
if (Datainfos!= null && datainfos[dataname]. ItemID!= null)
GetItemData ();
Else
Getnulldata ();

Implementation of the interface:
public string pagename
{
Get
{
return "Roledetail";
}
}

Public Datainfolist Datainfos
{
Get
{
if (viewstate["Datainfos"]!= null)
{
Return (datainfolist) viewstate["Datainfos"];
}
Else
return null;
}
Set
{
viewstate["Datainfos"] = value;
}
}

Public Hashtable Otherparams
{
Get
{
if (viewstate["otherparams"]!= null)
{
Return (Hashtable) viewstate["Otherparams"];
}
Else
return null;
}
Set
{
viewstate["Otherparams"] = value;
}
}

#endregion

Jump to another page (such as return list):
Server.Transfer ("rolelist.aspx");

So the functionality we need is realized.

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.