Learn PETSHOP3.0 (3) Query and SimplePager control

xiaoxiao2021-04-04  247

Serach function

Custom Control NavBar.ascx has a Form to declare a GET method, and automatically add input into the query string. Action is Search.aspx, there is a link in Form, click Go to the page search..ASPX. Search..ASPX contains a custom control SimplePager.ascx. SimplePager.ascx is initialized, call the OnLoad event, OnLoad Event calls the setPage method, triggered the onpageIndexchange event rewriting in SimplePager.ascx, which is this time access to the database, query all the requirements, then use paging, display some data.

The receiving method of the onpageIndexchanged event is defined on the Search..ASPX page. There are two definition methods: Define an onpageIndexchanged event in the SIMPLEPAGER.ASCX control of Search..ASPX, or define the PageChanged event in Search..ASPX.CS.

Here Microsoft uses Cache to improve the query function. Using the generated query string as the key of the Cache, the query result is the query result.

The rest is handed over to the SimplePager.ascx control.

2. SimplePager.ascx exported with TOGETHER

It can be seen that SimplePage inherits the Repeater. But Repeater does not have paging features, so SimplePage adds associated paging features.

The paging function is mainly completed in the onDatabase. Trigger the SIMPLEPAGE OONDATABINDING event when the page performs binding. For the first time, all the data is removed, and then according to the currentPageIndex (current page), Pagesize (number 10), the number of items (total number of data) is paging. Then call the Base class, Repeater's OONDATABINDING event, complete the binding of the data. The execution process is as follows: onload-> setpage-> onpageindexchanged-> ondatabinding-> render.

The second main analysis method is Render. Seeing the page written in Search.aspx is very irregular, as follows:

<

Headertemplate

>

<

TABLE

id

= "Data"

Cellpadding

= "0"

Cellspacing

= "0"

>

<

TBODY

>

<

TR

Class

= "Gridhead"

>

<

TD

>

Product ID

TD

>

<

TD

>

Name

TD

>

<

TD

>

Description

TD

>

TR

>

Headertemplate

>

<

ItemTemplate

>

<

TR

Class

= "GridItem"

>

<

TD

>

<%

# DataBinder.eval (Container.DataItem, "ID")

%>

TD

>

<

TD

> <

a

HREF

= 'Items.aspx? ProductID = <% # databinder.eval (container.DataItem, "ID")%

>

"

<%

# DataBinder.eval (Container.DataItem, "Name")

%>

a

>

TD

>

<

TD

>

<%

# DataBinder.eval (Container.DataItem, "Description")

%>

TD

>

TR

>

ItemTemplate

>

<

Footertemplate

>

TBODY

>

TABLE

>

Footertemplate

>

The label is not closed, and even there is cross. In fact, this is written, it is the HTML of the render method Write and a table. The main code of Render is as follows:

//

Write out the first part of the control, The Table Header

Writer.write (""

<

Table ID

=

'

Simplepage

'

Cellpadding

=

0

Cellspacing

=

0

> <

TR

> <

TD Colspan

=

2

>

");

Base

.Render (Writer);

//

Write Out a Table Row Closure

Writer.write (""

TD

>

TR

> <

TR

Class

=

Gridnav

> <

TD

>

");

//

Previous Buttons Are Required

......

//

Next Buttons Are Required

Writer.write

TD

> <

TD align

=

Right

>

);

//

Close The Table

Writer.write

"

"

);

The binding data output is mainly in Base.Render (Writer). Calling Render of Repeater. Note that the red number of modified codes can be seen in the later HTML code to see where they appear in their respective colors, and there is no cross and unacceptable labels in the code. It can also be found that the HTML code generated by the WRITER of the background code is written behind the HTML code generated directly from the page.

<

TABLE

id

= '

SimplePage 'Cellpadding

= 0

Cellspacing

= 0

>

<

TR

>

<

TD

Colspan

= 2

>

<

TABLE

id

= "Data"

Cellpadding

= "0"

Cellspacing

= "0"

>

<

TBODY

>

<

TR

Class

= "Gridhead"

>

<

TD

>

Product ID

TD

>

<

TD

>

Name

TD>

<

TD

>

Description

TD

>

TR

>

<

TR

Class

= "GridItem"

>

<

TD

>

FI-FW-01

TD

>

<

TD

> <

a

HREF

= 'Items.aspx? ProductID = FI-FW-01'

>

Koi

a

>

TD

>

<

TD

> <

IMG

Align

= "Absmiddle"

SRC

= "Images / pets / fish3.jpg"

>

Freshwater Fish from Japan

TD

>

TR

>

......

TBODY

>

TABLE

>

TD

>

TR

>

<

TR

Class

= Gridnav

>

<

TD

>

// Next Buttons Are Required

TD

>

<

TD

Align

= Right

>

// Previous Buttons Are Required

TD

>

TR

>

TABLE

>

p

>

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

New Post(0)