The primer is an extremely difficult question, just describes it, it will be very difficult, but I try it, I hope to describe it clearly:
Our company is a page logic using List / Detail, that is, a DataGrid lists, lists some items, click one of them, page jumps to the Detail page to see the details. The Detail page has a return button and returns to the list page after clicking. The data list in the list is usually filtered, such as XXX greater than 20, and then sorted. The problem is now this: user requirements, when returning from Detail to LIST, the state in the data list is unchanged. The company believes that this is a reasonable requirement, because the amount of data is too big, no one wants to return to List, you have to look from the first page. Also required, the Detail project just watching must be the current page of the list of List, not necessarily the page of the previous list data list; but if the current item is deleted in Detail, return must be entered That page of the List data list. What is more trouble is that users may jump to several related pages, these related pages may also have DataDrid, and then users will be held in the corresponding Detail page. And there may be multiple DataGrids in a list page. For example: Users have DataGrid_a1 and DataGrid_a2 in A_LIST, A_LIST, where data is filtered; then he views the item A1.1 this data, which enters A1.1_Detail; then jump into it again A1.1 related page A1.1_Detail2, this page has a DataGrid_a1.1, he performs screening, sorting; jump into another related page of A1.1, this page is a list page A1.1_List, where there is a DataGrid_a1 .11, it is clear that the data of this page is also filtering, the user sorts him; then enter one of the Detail pages A1.11.1, modify the data ... Ok, after these, he returned. First returned to A1.1_LIST, requiring DataGrid_a1.11 screening conditions, sorting the way, the one just visited on the DataGrid current page, before this item is on the second page, now may be on page 4 , Then display the fourth page; then return to a1.1_detail2, DataGrid_a1.1 screening conditions on this page, sort mode, the current page number is constant; return to A1.1_DETAIL, delete this A1.1 data; Finally returned to A_LIST, at this time, the screening conditions of the two DataGrid on this page are required, and the sorting mode is unchanged, and all previous page numbers are displayed. More terrible is that the real user does not necessarily return to the original road, so don't want these page status data to follow the principle of advancement. What should I do? This is very simple because it is in a Windows program, because from the first, a recorded Detail and its related information, usually a plurality of tabs of a form; even open another window The body, but it is just the HIDE (hidden), and then show it again when returning. In the final analysis, the Windows program is a stateful application, everything is very simple.
It is different from the Web. The web is stateless. Every time the page is returned, I don't know what the value is before, let alone the page, every page, I don't know my own Where (which page) is coming. The problem is analyzed such a difficult problem, and it seems to be dizzy, but to solve the problem, still have to use a clear brain. Basic Thoughts: Save the status data of the previous web page, jump to a new page, save the status data of the front page, and then retrieve the original data when returned. Let's take a look at the interaction data between the page. In general, it is the way of using URL parameters, but here is obviously lost, the URL has a length limit, and so many parameters, the assembly of the URL string will let your headache die. What should I do, I have to use another way: When I jump from a page, don't use Server.Transfer, and then use context.handler in the target web page, as shown below: Previous page Class is ABC, the latter page is dbc.aspx, define the public String CCC in the previous webline ABC; then use Server.Transfer (dbc.aspx) in the next web page when jumping in the ABC ((ABC ) Context.handler). Ccc can take a corresponding value. But it is obvious that there is still a problem in this, lacks versatility. What should I do with multiple page jumps? And the context.handler.gettype () method is unused, an exception occurs. Then define the interface. Define data on the need to interpret in an interface, multiple web pages implement the same interface. Query parameters, sort conditions, the current page to display, or display item IDs in the current page ... are defined in the implementation of the interface. But the problem is that the page is running while jump, and the data will continue to accumulate. If you jump from List1 to Detail1, then jump to list2, then jump to Detail2, this time Detail2 To save the data of the three web pages in front, These three web pages implements the same interface, which may result in the case where the data is covered. In general, when this is the case, it is designed a stack-like data structure. When it enters a new web page, the data of the original web page is pushed into the stack, which is called the protection site. It is a pity that this is not used, because the user will not necessarily return, if you use the way forward, you will find a web page to retrieve your own data but find that you can't retrieve it, you can get yourself The data. Only an array is used, and this array is still dynamic. Then, modify the interface just now, change it into a class DataInfo, then implement an interface, there is a dynamic array in the interface to store DataInfo. However, the element of the dynamic array is Object, which is too wide. I hope to strictly, only allow storage rather than messy stacks in the array, if you really implement a dynamic array, then you send DataInfo in the inside, I The stuff in the inside, it is still not taking a set. Then, the plurality of outsides the population, so that it only allows storage of DataInfo.
Can't pack directly in the interface, because I want to join some code to check if it is only DataInfo, or what is the other Dongdong. What should I do, then customize a class DataInfolist. And these classes are marked as serializable, which can be sequenced so that the status can be saved in ViewState. After the implementation of the solution is over, let's see how to implement him: Class DataInfo: This class is used to save the data status, in general, that is, each DataGrid corresponds to one: [serializable ()] public Class DataInfo
{
Private string dataname;
Private hashtable searchparams;
Private hashtable otherparams;
Private int currentpage;
Private string sortexpression;
PRIVATE STRING ITEMID;
Public DataInfo (String DataName)
{
This.dataname = DataName;
}
///
/// data name
/// summary>
Public String DataName
{
Get {return Dataname;}
}
///
/// query parameters
/// summary>
Public HashTable searchParams
{
Get {return searchparams;}
Set {searchparams = value;
}
///
/// Get other parameters
/// summary>
Public HashTable Otherparams
{
Get {return Otherparams;
Set {ioparams = value;
}
///
/// Get the current page
/// summary>
Public int currentpage
{
Get {return currentpage;
Set {currentpage = value;
}
///
/// Get sorting method
/// summary>
Public String Sortexpression
{
Get {return sortexpression;}
Set {sortexpression = value;}
}
///
/// Get the ID of the item to be displayed in the current page
/// summary>
Public String ItemID
{
Get {return itemid;}
Set {itemid = value;}
}
}
Class DataInfolist: This class package carries the dynamic array of DataInfo, limiting the data type of the array input and output [Serializable ()]
Public Class DataInfolist
{
Private arraylist datainfolist = new arraylist ();
Public DataInfo this [int index]
{
get
{
Return (DataInfo) DataInfolist [Index];
}
set
{
IF ((DataInfo) DataInfolist [Index]). DataName == Value.dataname || this [value.dataname] == null) {
DataInfolist [Index] = VALUE
}
Else
{
Throw new Exception ("There Have A DataInfo Used this name yet!");
}
}
}
Public DataInfo this [String Dataname]
{
get
{
For (int i = 0; i { IF (this [i] .dataname == Dataname) { Return this [i]; } } Return NULL; } set { For (int i = 0; i { IF (this [i] .dataname == Dataname) { THIS [I] = Value; Return; } } THIS.ADD (VALUE); } } Public Void Remove (DataInfo Value) { DataInfolist.remove (Value); } Public Void Remove (String Dataname) { DataInfo DataInfo = this [dataname]; IF (DataInfo! = NULL) { DataInfolist.remove (DataInfo); } } Public Bool Contains (DataInfo Value) { Return DataInfolist.Contains (Value); } Public Bool Contains (String DataName) { DataInfo DataInfo = this [dataname]; IF (DataInfo! = NULL) { Return True; } Return False; } Public void clear () { DataInfolist.clear (); } Public Int Add (DataInfo Value) { IF (this [value.dataname] == NULL) { Return DataInfolist.Add (Value); } Else { Throw new Exception ("There Have A DataInfo Used this name yet!"); } } Public Int Count { get { Return DataInfolist.count; } } } Interface ipageInfo: This interface is used in the page to implement data communication between the page. Public Interface ipageInfo { /// /// page name /// summary> String Pagename { Get; } /// /// Get data information /// summary> DataInfolist DataInfos { Get; } /// /// Get other parameters /// summary> Hashtable Otherparams { Get; } } How to use it on the page on the page on the page, how do you use these? First of all, List page implementation IpageInfo interface: Public class rolelist: system.web.ui.page, ipageInfo Then for each DataGrid instantiation DataInfo object: Protected DataInfo DataInfo = New DataInfo ("Role"); Next, write some processing DataGrid status code, I am using the properties: #Region data grid status 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.selected "= 0) { Return mydatagrid.datakeys [myDataGrid.selected ".toString (); } Else Return NULL; } set { INT pageIndex = mydatagrid.currentpageindex; BOOL FIND = FALSE; For (int J = 0; j { MyDataGrid.currentpageIndex = j; MyDataGrid.database (); for (int i = 0; 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; } } #ndregion in Take out the data of the previous page in PageLoad, pay attention, pay attention, from the front page Server.Transfer method: IpageInfo pointInfo = null; / / Remove the information of the previous page and save the data grid status Try { PageInfo = (ipageInfo) context.handler; } Catch {} IF (PageInfo! = NULL) { IF (PageInfo.uaryParams! = NULL) Otherparams = pageInfo.uaryparams; IF (PageInfo.datainfos! = null) { / / Save all DataGrid information DataInfos = pageinfo.datainfos; / / Remove the current data of DataGrid IF (pageinfo.datainfos [datainfo.dataname]! = null) { DataInfo = PageInfo.datainfos [DataInfo.dataname]; } } } Take the data out and then natural is processing, I set the value of the previous attributes, and there are many kinds of methods, which is not described here. Implementation of ipageInfo, When the DataInfos property is updated to update each page DataGrid DataInfo information to reflect the nearest changes: Public String Pagename { get { Return "rolelist"; } } Public HashTable Otherparams { get { IF (ViewState]! = 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.othesaParams = OtherDataParams; DataInfo.searchParams = SearchParams; DataInfo.sortexpression = sortexpression; DataInfolist [DataInfo.dataname] = DATAINFO; Return DataInfolist; } set { ViewState ["DataInfos"] = Value; } } Jump to other pages (such as the detailed page): Server.Transfer ("RoledgeTail.aspx"); For the Detail page, it will be relatively simple because there is basically no Datinfo update problem, which is designed to modify the itemid: Also implement the interface first: Public Class RoledTail: System.Web.ui.page, ipageInfo Then define two variables, a preserved data, a definition of the current data category, that is, to operate which DataInfo instance: Protected ipageInfo; protected string dataname = "role"; PageLoad Remove the previous page data and process the current item data: Try { PageInfo = (ipageInfo) context.handler; } Catch { } // Remove the current item ID 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 "rodingetail"; } } 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]! = null) { Return (Hashtable) ViewState ["Otherparams"]; } Else Return NULL; } set { ViewState ["OtherParams"] = VALUE } } #ndregion Jump to other pages (such as returning List): Server.Transfer ("RoleList.aspx"); This way we need to be implemented.