Get the App
SLTechnology News&Howtos  ›  Development  › 

.net how to implement GridView paging template

Shulou Source: shulou.com Published: 2022-06-03 05:40:05 10月02日 Update

This article mainly introduces how to achieve the .net GridView paging template, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The code is as follows:

/ / add the following attributes to the GridView (foreground or background depends on your habit.)

/ / implement paging

AllowPaging= "true"

/ / 10 rows per page of data

PageSize= "10"

/ / events triggered during paging

OnPageIndexChanging= "gvwDesignationName_PageIndexChanging"

/ / in the server event

Protected void gvwDesignationName_PageIndexChanging (object sender, GridViewPageEventArgs e)

{

GvwDesignationName.PageIndex=e.newIndex

BingDesignatioonName ()

}

/ / here I give a universal template for displaying paging.

Current No.:

/ / ((GridView) Container.NamingContainer) is to get the current control

Page / Total:

/ / get the total number of paged pages

Page

/ / if the page is the first page, then the link will not be displayed. At the same time, it corresponds to the command parameter CommandArgument with its own identification.

Home page

Previous page

/ / if the page is the end of the page, then the connection will not be displayed

next page

Last page

Go to th

Page

/ / CommandArgument here, even if you click the button, the e.newIndex value is 3.

/ / the code in the corresponding event is

Protected void gvwDesignationName_PageIndexChanging (object sender, GridViewPageEventArgs e)

{

/ / get the control

GridView theGrid = sender as GridView

Int newPageIndex = 0

If (e.NewPageIndex==-3)

{

/ / clicked the Go button

TextBox txtNewPageIndex = null

/ / GridView provides more API than DataGrid. You can use BottomPagerRow or TopPagerRow to get paging blocks. Of course, HeaderRow and FooterRow are also added.

GridViewRow pagerRow = theGrid.BottomPagerRow

If (pagerRow! = null)

{

/ / get the text control

TxtNewPageIndex = pagerRow.FindControl ("txtNewPageIndex") as TextBox

}

If (txtNewPageIndexpositions = null)

{

/ / get the index

NewPageIndex = int.Parse (txtNewPageIndex.Text)-1

}

}

Else

{

/ / clicked on other buttons

NewPageIndex = e.NewPageIndex

}

/ / prevent new index from overflowing

NewPageIndex = newPageIndex

< 0 ? 0 : newPageIndex; newPageIndex = newPageIndex >

= theGrid.PageCount? TheGrid.PageCount-1: newPageIndex

/ / get a new value

TheGrid.PageIndex = newPageIndex

/ / rebind

BingDesignatioonName ()

}

Thank you for reading this article carefully. I hope the article ".net how to implement GridView pagination template" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles templates events buttons controls at the same time more indexes code values interests foreground parameters background commands that is properties totals data friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Apple MariaDB Huawei