-Teach you how to write the Ajax-driven DataGrid Control (3)

Source: Internet
Author: User
From http://www.cnblogs.com/wfyfngu/archive/2007/10/10/918931.html

In the previous article, we achieved the goal of converting an object-type data source into a datatable. Next, we will keep the data sources until we confirm they are no longer used.
It is easy to retain the data source. We use hashtable to cache the data. However, when will the data source be retained? How can we accurately determine that the data source is no longer used? We will discuss it later.
1.1 retain the data source ajaxgridhelper. csusing system;
Using system. collections;

Namespace wfyfngu. Web. UI
{

/// <Summary>
/// Ajaxgridhelper abstract description.
/// </Summary>
[Serializable]
Internal class ajaxgridhelper
{

// Master table
// Key: Unique Identifier of the client, used to distinguish users
// Value: Auxiliary table
// -- Auxiliary table
// Key: the unique identifier of the control.
// Value: datagridsourceinfo object
Private Static hashtable cachedsource = new hashtable (100 );

// Customer list
Private Static hashtable cachedclient = new hashtable (100 );

/// <Summary>
/// Allowed inactive time (minutes)
/// If the data source is not destroyed normally, call the corresponding code to destroy it after this time
/// When the client communicates with the server within this time period, it is considered to be online
/// If the client does not communicate with the server during this time period, all its data will be deleted.
/// </Summary>
Private Static int timeout = 720;


}

}

In the code above, we used two hash tables, in which the table cachedsource is used to store the data source, and the table cachedclient is used to store the status information of the ajaxgrid client. They have a randomly generated identical guid as the key. Join us in. the ASPX page loads an ajaxgrid control, and the server assigns it a unique guid as the identifier. This guid generates a key-value pair in the form of a key in both cachedsource and cachedclient, and store necessary information. See the table below:

Hash table Key Value Description
Cachedsource B9fbb335-c2d8-4aee-bd2c-3518e7c27a3e New ajaxgridsourceinfo (...)
Cachedclient B9fbb335-c2d8-4aee-bd2c-3518e7c27a3e Control Creation Time

The following is the source code of ajaxgridsourceinfo. CS.

Using system;

Namespace wfyfngu. Web. UI
{
/** // <Summary>
/// Ajaxgridsourceinfo abstract description.
/// </Summary>
[Serializable]
Internal class ajaxgridsourceinfo
{
Private string [] _ captions = NULL;
Private object _ datasource;

/** // <Summary>
///
/// </Summary>
Public ajaxgridsourceinfo (){}

/** // <Summary>
///
/// </Summary>
/// <Param name = "captions"> title </param>
/// <Param name = "datesource"> data source </param>
Public ajaxgridsourceinfo (string [] captions, object datesource)
{
_ Captions = captions;
_ Datasource = datesource;
}

/** // <Summary>
/// Obtain the title set of ajaxgrid
/// </Summary>
Public String [] captions
{
Get {return _ captions ;}
}

/** // <Summary>
/// Obtain the data source of the ajaxgrid User Control
/// </Summary>
Public object datasource
{
Get {return _ datasource ;}
}

}
}

Now, we have saved the data source, and we will discuss the issues left behind.
1.2 data source destruction
Data sources should be destroyed at appropriate time, if too early, of course not; if too late, it will inevitably cause a waste of memory. We provide two mechanisms to ensure that data sources that are no longer in use can be destroyed.
1) The client notifies the server that the specified data source is no longer in use.
2) If the client does not work as expected (this is possible because the client code is untrusted), we will clear expired data as agreed in advance.

>>To be continued! Control source code and a brief introduction, please log on to the http://www.codeassistant.net/wfygrid/ <

Related Article

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.