Pagination with gridview control

How to implement pagination in gridview.

Method 1

SELECTDISTINCTTOP8CategoryID

FROMtbl_Proct_Procts

WHERE(UserID=73)AND(CategoryID>

( SELECTMAX(categoryid)

FROM(SELECTDISTINCTTOP16categoryid

FROMtbl_proct_proctswhereuserid=73

ORDERBYcategoryid) ASb))

ORDERBYCategoryID

–Method 2

selecttop10*from[orderdetails]

whereorderid>all(selecttop10orderidfrom[ orderdetails]orderbyorderid)

orderbyorderid

The following is from CSDN ————————————-

Pagination of SQLServer stored procedures, an issue that It’s been discussed for a few years now, and a lot of friends are asking me about it, so here’s my opinion

Create the table:

CREATETABLE[TestTable](

[ID][int]IDENTITY(1,1)NOTNULL,

[FirstName][ nvarchar](100)COLLATEChinese_PRC_CI_ASNULL,

[LastName][nvarchar](100)COLLATEChinese_PRC_CI_ASNULL,

[Country][nvarchar] (50)COLLATEChinese_PRC_CI_ASNULL,

[Note][nvarchar](2000)COLLATEChinese_PRC_CI_ASNULL

)ON[PRIMARY]

GO

SETIDENTITY_INSERTTestTableON

declare@iint

set@i=1

while@i<=20000

begin

insertintoTestTable([id], FirstName,LastName,Country,Note)values(@i,’FirstName_XXX’,’LastName_XXX’,’Country_XXX’,’Note_XXX’)

set@i=@i+1

end

< p>SETIDENTITY_INSERTTestTableOFF

————————————-

Paging Scheme 1: (Using NotIn and SELECTTOP paging)

Statement form:

SELECTTOP10*

FROMTestTable

WHERE(IDNOTIN

(SELECTTOP20id

FROMTestTable

ORDERBYid))

ORDERBYID

SELECTTOP page size*

FROMTestTable

WHERE(IDNOTIN

(SELECTTOP page size*page id

FROM table

ORDERBYid))

ORDERBYID

————————————-

Pagination scheme II: (using ID greater than what and SELECTTOP paging)

Statement form:

SELECTTOP10*

FROMTestTable

WHERE(ID>

(SELECTMAX(id)

FROM(SELECTTOP20id

FROMTestTable

ORDERBYid)AST))

ORDERBYID

SELECTTOP PageSize*

FROMTestTable

WHERE(ID>

(SELECTMAX(id)

FROM(SELECTTOP PageSize*PageID

FROMTable

ORDERBYid )AST))

ORDERBYID

————————————-

Pagination Scheme 3: (Pagination using SQL’s Cursor Stored Procedure)

createprocereXiaoZhengGe

@sqlstrnvarchar(4000),–query string

@currentpageint,–page N

@pagesizeint–rows per page

as

setnocounton

declare@ P1int,–P1 is the id of the cursor

@rowcountint

execsp_cursoropen@P1output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcountoutput

selectceiling(1.0*@rowcount/@pagesize)asTotalPages–,@rowcountasTotalRows,@currentpageasCurrentPage

set@currentpage=(@currentpage-1)*@pagesize+1

execsp_cursorfetch@P1,16,@currentpage,@pagesize

execsp_cursorclose@P1

setnocountoff

Other scenarios: if you don’t have a primary key, you can use a temporary table, and also can be done with option 3, but it will be less efficient.

It is recommended to optimize with primary keys and indexes, the query efficiency will increase.

Through the SQL Query Analyzer, showing a comparison: my conclusion:

Pagination scheme II: (using ID greater than how many and SELECTTOP paging) the most efficient, need to splice SQL statements

Pagination scheme I: (using NotIn and SELECTTOP paging) the second most efficient, need to splice SQL statements

Paging scheme three: (using SQL’s cursor stored procedure paging) the worst efficiency, but the most versatile

In the actual situation, to be analyzed specifically.

如何实现GridView左右滑动分页的效果

gridview实现横向分页滑动效果的两种实现方案

DisplayMetricsdm;

privatevoidsetValue(){

intcount=gridAdapter.getCount();

intnumColumns=(count%2==0)?count/2:count/2+1;

LinearLayout.LayoutParamsparams=newLinearLayout.LayoutParams(numColumns*dm.widthPixels/5,LinearLayout.LayoutParams.WRAP_CONTENT);

gridView.setLayoutParams(params);

gridView.setColumnWidth(dm.widthPixels/5);

//gridView.setHorizontalSpacing(hSpacing);

gridView.setStretchMode(GridView.NO_STRETCH);

gridView.setNumColumns(numColumns);

}

privatevoidgetScreenDen(){

dm=newDisplayMetrics();

getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

}

/**

*初始化gridview

*/

@SuppressLint(“WrongViewCast”)

privatevoidinitGridView(finalJSONArrayarray){

gridAdapter=newHomeMainGridAdapter(getActivity(),array,null);

gridView=(GridView)findViewById(R.id.gview);

horizontalScrollView=(HorizontalScrollView)findViewById(R.id.scrollView);

horizontalScrollView.setHorizontalScrollBarEnabled(false);//隐藏滚动条

getScreenDen();

setValue();

gridView.setSelector(newColorDrawable(Color.TRANSPARENT));

gridView.setAdapter(gridAdapter);

}

How to use the paging feature of Gridview?

usingSystem;

usingSystem.Data;

usingSystem.Configuration;

usingSystem.Web;

usingSystem.Web. Security;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.WebControls.WebParts;

usingSystem.Web.UI.HtmlControls;

usingSystem.Data.SqlClient;//import namespace

publicpartialclass_Default:System.Web.UI.Page

{

protectedvoidPage_Load(objectsender,EventArgse)

{

GridView1.AllowPaging=true;//must remember to set it to true so that paging can occur

GridView1.PageSize=5;//Set to display 5 data per page

// I use SqlServer comes with the database: pubs, and the table: employee for testing

using(SqlConnectioncon=newSqlConnection (“server=. ;database=pubs;integratedsecurity=sspi”))

{

con.Open();//put the hit link

DataSetds=newDataSet();//dataset, used to store offline data

SqlDataAdapterSqlda=newSqlDataAdapter(“select*fromemployee”,con);

Sqlda.Fill(ds);//fill the first table of the data set

GridView1.DataSource=ds )

GridView1.DataSource=ds;//The data source of control GridView1 is declared to be the first table of ds

GridView1.DataBind();//This should be remembered to add the —– to bind to the control GridView1

}

}

//Event generated by clicking on the Pagination button

protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse)

{

GridView1.PageIndex=e.NewPageIndex;

GridView1.DataBind();

}

}

How to achieve gridview paging style Previous12345Next

Inserted in the gridview control PagerTemplate, attached code: current:Page/Total:Page HomePreviousNextLastIn .cs file to insert the implementation of the function, attached code: protectedvoidgvwDesignationName_PageIndexChanging(objectsender,GridViewPageEventArgse){// Get the control…

有关gridview翻页操作的的问题。

首先,用gridview自带的分页可以实现。如果不会用gridview自带的分页可以上网查询下。其实就是添加几个事件。用gridview分页的代码如下:

#region分页

privatevoidpanan()

{

if(this.dgzy.PageCount==1||this.dgzy.CurrentPageIndex==this.dgzy.PageCount-1)

{

this.next_page.Enabled=false;

this.last_page.Enabled=false;

}

else

{

this.next_page.Enabled=true;

this.last_page.Enabled=true;

}

if(this.dgzy.CurrentPageIndex==0)

{

this.first_page.Enabled=false;

this.pre_page.Enabled=false;

}

else

{

this.first_page.Enabled=true;

this.pre_page.Enabled=true;

}

lbl_curr_page.Text=Convert.ToString(this.dgzy.CurrentPageIndex+1);

lbl_pagecount.Text=this.dgzy.PageCount.ToString();

}

protectedvoidfirst_page_Click(objectsender,EventArgse)

{

this.dgzy.CurrentPageIndex=0;

this.binddg(Session[“sql”].ToString());

}

protectedvoidpre_page_Click(objectsender,EventArgse)

{

if(this.dgzy.CurrentPageIndex!=0)

{

this.dgzy.CurrentPageIndex=this.dgzy.CurrentPageIndex-1;

this.binddg(Session[“sql”].ToString());

}

}

protectedvoidnext_page_Click(objectsender,EventArgse)

{

if(this.dgzy.CurrentPageIndex!=this.dgzy.PageCount-1)

{

this.dgzy.CurrentPageIndex=this.dgzy.CurrentPageIndex+1;

this.binddg(Session[“sql”].ToString());

}

}

protectedvoidlast_page_Click(objectsender,EventArgse)

{

this.dgzy.CurrentPageIndex=this.dgzy.PageCount-1;

this.binddg(Session[“sql”].ToString());

}

#endregion