.Net production with sorting, pagination and an example of the many records to select and delete: Lo Date: 2003-11-04 Contact: robert_luoqing@hotmail.com I. Overview Second, the realization of the functions of three constraints four principles Figure 5. Production process (example) six, original code 1, overview: DataGrid is often used in web applications, but the DataGrid control itself is sorted by the arch, paging function for a large number of records, according to its practice It is unrealistic, such as a table has 200,000 records, according to the sorting of DataGrid itself, the principle of paging, you must retrieve all records, and make a paging, which is a challenge for the server's memory and response. This thesis provides such a solution that onlys the response time is greatly improved only from the database, so the response time is greatly improved, and the memory overhead can be reduced. Second, the implementation function: 1. Display the data retrieved from the database on the page on the page (displays the DataGrid control). 2. Pipeting the record (you must make paging within the database, that is, the number of records per page, the number per page) 3, record the recording of the pilot page) 3. After clicking the DataGrid header to achieve the reordering display, There is a click to order in descending order, click on the second time (not sorting the displayed record, but re-reaching the criterion in the database and sorted by specified order) 4, you can click DataGrid Checkbox box to implement all-elective and full-selection functions, support group operations (such as delete, transfer, etc.), restricting the conditions 1, the database table must have a key field or have a unique field. Fourth, Schematic: Function 2: Function 3: Function 4: V. Production Process (Sample): 1, Database Structure: This example is the database northwind with SQL Server as an example, Table as Customers 2, encoding process: 1 The interface is as follows 2, the code is written: 1. First, the user will add a form. 2. Place a five LinkButton control on the form, and set the ID to: lkbdel, linkbuttonpreview, linkbuttonnext, linkbuttonlast, linkbuttonfirst, setting each control's text property is: "Delete", "Home", "Previous", "Next", and "Last", place the location as shown above; simultaneously put a DataGrid control on the form, the name of the control is: DGList 3, set the DGList control to true, the AutoGenarateColumes property is set to False The DataKeyField property is set to Customerid. The Width property is set to 100%, and the columns of setting the DGList control are as follows:
asp: checkbox> headertemplate>
Itemtemplate>
asp: templateColumn>
Columns>
One of the first columns is necessary, other columns can increase or delete themselves according to the situation. In the upper code, the selection of CHECKBOX in the upper code implements all the selection or all-in-one functions of all display items are implemented by a JavaScript's Checkallorno (this) letter, and the specific function body is as follows:
Function Checkallorno (O)
{
Var a = o; while (true)
{
VAR a = a.parentelement;
IF (a == NULL)
{
Break;
}
IF (a == "undefined")
{
A = NULL;
Break;
}
IF (a.tagname == "table")
{
Break;
}
}
IF (a! = null)
{
For (i = 0; i { For (j = 0; j Var var1 = a.rows [i] .Cells [0] .children [j]; IF (var1.tagname == "input") { IF (var1.type == "checkbox") { Var1.checked = o.checked; } } } } } } script> Simultaneous setting of dglist's SortCommand for dglist_sortcommand () to see the original code. 4, setting LKBDEL's Click event is as follows: lkbdel_click (ibject sender, system.eventargs e), of course, the event name You can name, and set LinkButtonPreView, linkbuttonnext, linkbuttonlast, linkbuttonfirst's Click event for the same function (how to Set the event, please see MSDN). The function name is: dglist_sortcommand (Object Source, System.Web.ui.WebControls.DataGridSortCommandEventArgs E); Each event's specific implementation see the source code, putting two variables in the class as follows: // This is displayed per page Records. PRIVATE INT RecordperPage = 6; // This variable is connected to the database protected string m_cnnstr = "data source = Robert / Robert; initial catalog = Northwind; User id = sa; pwd ="; 5, adding the following code page_Load event: private void Page_Load (object sender, System.EventArgs e) { IF (! this.ispostback) { /*this.viewstate ["totalRecord "] * How many records are used to record a total of total * * / THIS.VIEWSTATE ["TotalRecord"] = getTatolRecordNumber (); /*this.viewstate ["totalRecord "] * Used to record the current display of the sum * * / THIS.VIEWSTATE ["currentpg"] = 1; /*this.viewstate["stiT "] * Used to store current sorting strings * * / This.ViewState ["sort"] = ""; // initializes the status of the guide. SetGuide (NULL); // The record is displayed for the first time. SHOWDATA (); } } Where getTatolRecordNumber () is retrieved, setGuide (null); is the state of setting the paging-related button, showdata (); is used to set the DGList control data source, the specific implementation of the two people, please see the source code . aspx original code: <% @ Page language = "c #" Codebehind = "Pagination.aspx.cs" AutoEventWireup = "false" Inherits = "SortAndPagination.Pagination"%> <% @ Register TagPrefix = "iewc" Namespace = "Microsoft. Web.ui.WebControls "assembly =" Microsoft.Web.ui.WebControls, Version = 1.0.2.226, Culture = neutral, publickeyToken = 31bf3856ad364e35 "%>
Function Checkallorno (O)
{
VAR A = O;
While (True)
{
VAR a = a.parentelement;
IF (a == NULL)
{
Break;
}
IF (a == "undefined")
{
A = NULL;
Break;
}
IF (a.tagname == "table")
{
Break;
}
}
IF (a! = null)
{
For (i = 0; i { For (j = 0; j { Var var1 = a.rows [i] .Cells [0] .children [j]; IF (var1.tagname == "input") { IF (var1.type == "checkbox") { Var1.checked = o.checked; } } } } } } script> HEAD>