Eric's Ultra Efficiency Data Patement (Illustration + Code) ^

xiaoxiao2021-03-06  59

Data table structure:

Megaid Int Identity (1, 1) Not Null Primary Key Clustered

MegaGuid Char (36) Not Null Index

Data generating script:

Declare

@i

int

Set

@i

=

1

While

@i

<

1000001

Begin

Insert

INTO

MEGATABLE (MegaGuid)

Values

(

NewID

())

Set

@i

=

@i

1

End

Go

C # code:

DateTime StartTime;

Void

Page_init (Object Sender, Eventargs E)

{StartTime = datetime.now;}

protected

Override

Void

Render (HTMLTextWriter Writer)

{Base.Render (Writer); Response.write ("This page Execute Time:" (DateTime.now - StartTime);

int

Records

=

10,000

;

int

Pages

=

10

;

int

PageSize

=

15

; SqlConnection Conn

=

New

SqlConnection

"

Server = (local); data = megadata; user ID = sa; password = xxx

"

);

Void

Page_load

Object

Sender, Eventargs E)

{If (! Ispostback) {dgbind (getsqlstring (1));} int firstpage = int.parse (hidfirstpage.value); pnlbuttons.controls.add (getpager (firstpage)); lblprompt.text = data extraction range: < B> SELECT TOP " Records.toString () " Megaid from megatable order by megaguid ";

String

Getsqlstring

int

SELECTEDPAGE

{String [] IdSstray; string sqlstr; if (session ["idstr"]! = Null) {idSstray = session ["idstr"]. Tostring (). Split ('#');} else {sqlstr = "SELECT TOP " records.ToString () " megaid FROM megatable ORDER BY megaguid "; SqlCommand cmd = new SqlCommand (sqlStr, conn); conn.Open (); SqlDataReader dr = cmd.ExecuteReader (); StringBuilder sb = new StringBuilder (" "); Int N = 1; while (Dr.Read ()) {if (n% pagesize == 0) {sb.append (DR [0] .tostring () " # ");} else {sb. Append (DR [0] .tostring () ",");} n ;} Dr.close (); conn.close (); Sb.Remove (sb.Length - 1, 1); idSstraray = sb.toString (). split ('#'); session ["idstr"] = sb.toString ();} hidpageCount.Value = IDSstray.length. Tostring (); sqlstr = "SELECT Megaid, MegaGuid from MegaTable Where Megaid in (" IDSstray [SELECTEDPAGE - 1] ")"; SQLSTR = "Order By MegaGuid"; Return Sqlstr;} Panel getPager

int

Firstpage)

{INT pageCount = int.parse (hidpagecount.value); Panel pnlpager = new panel (); pnlpager.controls.add (new literalcontrol ("
total" pageCount.toString () "page"); pnlpager .Controls.add (GetLinkButton ("FST", "Home", "PGBTN", "1")); PNLPager.Controls.Add (New LitralControl (")); if (FirstPage> 0) {PNLPager.Controls. Add ("pre", "front" pages.tostring () "PGBTN", (FirstPage - Pages 1); pnlpager.controls.add (New LitralControl) "));} For (int i = firstpage 1; i pagecount) {Break;} pnlpager.controls.add (getLinkButton (I.toToString ()," [" I.tostring () "] "," pgbtn ", I.toTOString ())); pnlpager.controls.add (new literalcontrol ("));} if (FirstPage PAG ES

String

LBID,

String

LbText,

String

lbcmdname,

String

lbCmdArg) {LinkButton lb = new LinkButton (); lb.ID = lbCmdName lbId; lb.Text = lbText; lb.CommandName = lbCmdName; lb.CommandArgument = lbCmdArg; lb.Command = new CommandEventHandler (pageTurn); return lb }

Void

PageTurn

Object

Sender, CommandEventArgs E)

{LinkButton lb = (LinkButton) sender; int selectedPage = int.Parse (lb.CommandArgument); int firstPage = selectedPage / pages * pages; firstPage = (selectedPage% pages == 0) (firstPage - pages):? FirstPage; hidFirstPage .Value = firstPage.ToString (); dgBind (getSqlString (selectedPage)); pnlButtons.Controls.RemoveAt (pnlButtons.Controls.Count - 1); pnlButtons.Controls.Add (getPager (firstPage)); lb = (LinkButton) pnlButtons .Controls [pnlbuttons.controls.count - 1] .FindControl ("pgbtn" selectedPage.tostring ()); lb.enabled = false;}

Void

DGBind

String

SQLSTR)

{SqlDataAdapter Da = New SqldataAdapter (Sqlstr, Conn); DataTable DT = New DataTable (); conn.open (); da.fill (dt); conn.close (); da.dispose (); DG.DataSource = DT DG.DATABIND ();

Void

DG_ItemDatabase

Object

Sender, DataGriditeMeventArgs E)

{DG.Controls [0] .enableviewState = false;

ASPX code:

<%

@ Import namespace = "system.text"

%>

<%

@ Import namespace = "system.data.sqlclient"

%>

<%

@ Import namespace = "system.data"

%>

<%

@ Page language = "c #"

%>

DOCTYPE HTML PUBLIC "- // W3C // DTD XHTML 1.1 // en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"

>

<

HTML

>

<

HEAD

>

<

Title

>

Pager

Title

>

<

Script

Runat

= "Server"

>

// Insert the C # code above

Script

>

<

Style

>

Body {} {font-size: 9pt; font-family: Tahoma, Song; Text-align: center} TD {} {font-size: 9pt; font-family: Tahoma, Song; Text-align: center}

Style

>

HEAD

>

<

Body

>

<

FORM

id

= "Form1"

Runat

= "Server"

>

<

Div

>

<

ASP: Label

id

= "LBLPROMPT"

Runat

= "Server"

TEXT

= "?"

EnableViewState

= "False"

enabletheming

= "True"

>

ASP: Label

>

<

Br

>

<

ASP: PANEL

id

= "pnlbuttons"

Runat

= "Server"

Width

= "560px"

>

<

INPUT

id

= "hidfirstpage"

Type

= "hidden"

Value

= "0"

Runat

= "Server"

> <

INPUT

id

= "HIDPAGECOUNT"

Type

= "hidden"

Runat

= "Server"

>

<

ASP: DATAGRID

id

= "DG"

Runat

= "Server"

Width

= "100%"

OntemDatabase

= "DG_ItemDatabase"

Cellpadding

= "4"

Backcolor

= "White"

Borderwidth

= "1px"

Borderstyle

= "None"

Bordercolor

= "# Cc9966"

AutogenerateColumns

= "False"

PageSize

= "5"

>

<

Footerstyle

Forecolor

= "# 330099"

Backcolor

= "# Fffcc"

>

Footerstyle

>

<

HEADERSTYLEFONT-BOLD

= "True"

Forecolor

= "# Fffcc"

Backcolor

= "# 990000"

>

HEADERSTYLE

>

<

Pagerstyle

Horizontalalign

= "Center"

Forecolor

= "# 330099"

Backcolor

= "# Fffcc"

>

Pagerstyle

>

<

SelectEdItemStyle

Font-bold

= "True"

Forecolor

= "# 663399"

Backcolor

= "# Ffcc66"

>

SelectEdItemStyle

>

<

ItemStyle

Forecolor

= "# 330099"

Backcolor

= "White"

>

ItemStyle

>

<

Columns

>

<

ASP: BoundColumn

Datafield

= "megaid"

Headertext

= "Megaid"

>

ASP: BoundColumn

>

<

ASP: BoundColumn

Datafield

= "MegaGuid"

Headertext

= "MegaGuid"

>

ASP: BoundColumn

>

Columns

>

ASP: DATAGRID

>

ASP: PANEL

>

Div

>

<

Br

>

<

ASP: HyperLink

id

= "lnkreeload"

Runat

= "Server"

Width

= "80px"

NavigateURL

= "Pager.aspx"

EnableViewState

= "False"

>

Overload

ASP: HyperLink

>

FORM

>

Body

>

HTML

>

转载请注明原文地址:https://www.9cbs.com/read-118397.html

New Post(0)