Asp.net Study Notes: aspnetpager

Source: Internet
Author: User

Self-Learning Asp.net Website creation time is not long , In the learning process , Paging becomes a big problem , Asp.net The Visual Effects of component distribution vary greatly. , It is not easy to use. ( Maybe my technology is too bad. ), So I chose to find a dedicated paging component on the Internet. , Selected here Aspnetpager, This one from ShaanxiProgramDeveloped and encapsulated DLL File , This paging component is easy to use. , And integrated with the storage process Generation Tool , This is very helpful for me. . Although this component is easy to use , However, it may take some time for a newbie to start using this component. ( I spent half a day ), Now I will introduce the usage of this component in detail. :

I,Component parameters used

RecordcountTotal number of records

StartrecordindexStart Record Number (used in Stored Procedure)

EndrecordindexEnd record number (used in Stored Procedure)

II,Usage

InPage_load.

Example:

Public Partial Class Default4: System. Web. UI.Page

{

DataoperationMydo =New Dataoperation();

If(! Ispostback)//Run the command if it is not a return request. It is used for initialization.

{

DataoperationMydo1 =New Dataoperation();//Instantiate database connection

StringSqlstr1 ="Exec FY 0, 0, 1";//DefinitionSQLStatement.FYStorage Functions

//InitializationRecordcount,Mydo1.getexesqlcountReturnsInt

Aspnetpager1.recordcount = mydo1.getexesqlcount (sqlstr1 );

//DefinitionSQLStatement.FYStorage Functions

StringSqlstr ="Exec fy"+ Aspnetpager1.startrecordindex +","+ Aspnetpager1.endrecordindex +", 0";

//ToGridview1Specify a data source,Mydo. getexesqldatatableReturnsDatatable

This. Gridview1.datasource = mydo. getexesqldatatable (sqlstr );

This. Gridview1.databind ();

}

Protected VoidAspnetpager1 _ pagechanged (ObjectSender,EventargsE)

{// Aspnetpager1ComponentPagechangedEvent

StringSqlstr ="Exec fy"+ Aspnetpager1.startrecordindex +","+ Aspnetpager1.endrecordindex +", 0";

This. Gridview1.datasource = mydo. getexesqldatatable (sqlstr );

This. Gridview1.databind ();

}

}

There are many other functions in this component. When you use it, you will find that the settings are visualized. I will not talk about them here. below is the stored procedure used in this article, I believe you can understand the aboveCodeThis article is also attached.

Stored Procedure:

Alter procedureFY

(@ StartindexInt,

@ EndindexInt,

@ DocountInt)

As

Set nocount on

If(@ Docount = 1)

Select count(*)FromXt_article

Else

Begin

Declare@ IndextableTable(IDInt identity(1, 1), NIDInt)

Set rowcount@ Endindex

Insert@ Indextable (NID)SelectIDFromXt_article OrderIDASC

Select*FromXt_article o, @ indextable tWhereO. ID = T. Nid

AndT. IDBetween@ StartindexAnd@ EndindexOrderT. ID

End

Set nocount off

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.