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