Introduction: DataGrid as part of the ASP.NET business product, which has mentioned many easier development methods for developers, but DataGrid is like a cane, although he can help you walk, and he restricts you can't run. Many times, projects or users' requirements make DataGrid look very bloated and restricted. It is such a project that in order to meet the needs of all my customers, I have to temporarily do not use this drag-grained development method.
Background: I have recently faced a lot of projects that they will use, which requires that a quantity is still a larger trading plan data set. The most basic content is that the user needs to see a list of plans that can control up and down by buttons. The up and down button enables the form to replace the data content on the upper page inside. Moreover, the customer needs page return to keep the minimum number, which is this requirement, let me change my original idea --- through a DropDownList based on the return selection different options to change the idea of the paging.
I later solved my problem by extending an ALBERTO's Master Detail DDL Project article on the Code Project. However, this paging still has some problems, I tried a lot of technology about DataGrid and Repeaters, but they are all more complicated, than a few hundred lines that I think the actual needs, these methods are more excellent in the method is Andrew Merlino's Article and Code.
Finally, I realized that Table in HTML can work just as the DIV layer. By setting the Table's Style = "Display: None" property, I can hide this table on the client. What I have to do is to create such a table for each page. These tables contain only one column header line, and the independent cell stored. There is also a set of Continuous storage of the table, which I can place anything (such as my demo) in the content cell. All of these are dynamically created a JavaScript to process the client's flip request
Using code: In my example, the internal strength is very simple, including a separate aspx with code-behind, code-behind code less than 250 lines, below is a simple step of the solution
Get a DataSet with a DataTble
The number of pages based on the number of records and the number of rows-defined per page,
Create a container Table for each page
Create a child table for each row
Add a sub-table to the container TABLE
Add this container Table to the page and set Runat = "Server".
Add JavaScript to the page
In this example I use the Northwind database in SQL Server, you can set the database you define by changing the connection string.
Private void buildtables ()
{
Numitems = ds.tables [0] .ROWS.COUNT;
PageSize = int32.parse (txtpagesize.text);
// DETERMINE NUBER OF PAGES MINUS Any Leftover Records Long
Pages = (NumItems / pagesize);
// Save this Number for Future Reference Long
WHOLEPAGES = NumItems / Pagesize;
// determine Number of Leftover Records Int
Leftover = NumItems% pageSize;
// if there is defrase page count by Oneif (Leftover> 0)
{
Pages = 1;
}
THIS.BUILDJSFUNCTIONS (Convert.Toint 32 (PAGES));
INT Startofpage = 0;
Int endofpage = pagesize;
THIS.LBLPAGES.TEXT = pages.tostring () "Pages";
THIS.LBLRECORDS.TEXT = NumItems.toString () "Records";
For (int P = 1; P <= pages; p )
{
// Create Page Tables
HTMLTable TBLPAGE = New HTMLTABLE ();
HTMLTABLEROW TROW = New HTMLTABLEROW ();
HTMLTABLEROW HROW = New HTMLTABLEROW ();
Htmltablecell hcell = new htmltablecell ();
Hcell.innerhtml = "Page" p.toString () ""
Hrow.cells.Add (HCell);
TBLPAGE.ROWS.ADD (HROW);
HTMLTablecell Tcell = New HTMLTableCell ();
TBLPAGE.ID = "Page" P;
IF (p == 1)
TBLPAGE.Style.Add ("Display", "Block");
Else
TBLPAGE.Style.Add ("Display", "None");
// Now, I want to get a row formatted as a table. This
// is Capability Is Really The Whole Reason for this Project.
For (int I = startofpage; i <= endofpage; i )
{
// Make Sure the Another Row in the dataset
IF (i Tcell.Controls.Add (FillPages (i)); } Trow.cells.Add (TCELL); TBLPAGE.ROWS.AD (TROW); HTMLTablecell Tdpages = (HTMLTableCell) FindControl ("TDPages"); TDPages.Controls.add (TBLPAGE); // set the page number STARTOFPAGE = endofpage 1; Endofpage = endofpage pagesize; } } The above method loops calls the FillPages (int RECORD) method, returns a received table for the current row,. There is also a better way to get how much DataTable is available. The entire project is very simple Private HTMLTable Fillpages (int Record) { Htmltable tblnew = new htmltable (); HTMLTABLEROW R1 = New HTMLTableRow (); HTMLTABLEROW R2 = New HTMLTableRow (); HTMLTableCell C1 = New HTMLTableCell (); HTMLTableCell C2 = New HTMLTableCell (); HTMLTableCell C3 = New HTMLTableCell (); // Format the Cells TBLNEW.BORDER = 1; TBLNEW.CELLSPACING = 0; TBLNEW.CELLPADDING = 3; TBLNEW.WIDTH = "520px"; C1.COLSPAN = 2; c1.bgcolor = "Silver"; C1.Style.Add ("Font-Color", "White"); C2.Width = "80%"; C3.Width = "20%"; // Fill Cells C1. Innerhtml = "Product ID:" DS.Tables [0]. ROWS [RECORD] [0] .tostring (); C2.INNNERHTML = DS.TABLES [0] .ROWS [RECORD] [1] .tostring (); C3.INNERHTML = DS.TABLES [0]. ROWS [RECORD] [2] .tostring (); // Assign Cells to Rows R1.cells.Add (C1); R2.cells.Add (C2); R2.Cells.Add (C3); // Assign Rows to Table TBLNEW.ROWS.ADD (R1); TBLNEW.ROWS.ADD (R2); Return TBLNEW; } BuildTables Call the buildjsfunctions method to get the current generation, then add the corresponding JavaScript to this page, this method can be split into four parts for each execution situation, I will include them in order to simply Inside the function, you can make it more need to split them in the future. Private Void Buildjsfunctions (int pages) { INT MAXPAGE = PAGES 1; Stringbuilder s =