Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize GridView pagination

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to implement GridView pagination. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

To add to the GridView

/ / implement paging

AllowPaging= "true"

/ / 10 rows per page of data

PageSize= "10"

/ / events triggered during paging

OnPageIndexChanging= "gvwDesignationName_PageIndexChanging"

In server events

The copy code is as follows:

Protectedvoid gvwDesignationName_PageIndexChanging (object sender, GridViewPageEventArgs e)

{

GvwDesignationName.PageIndex=e.newIndex

BingDesignatioonName ()

}

Here I give a general template for displaying paging (search on the Internet, give your own comments)

The copy code is as follows:

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 event is

The copy code is as follows:

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 is the end of the article on "how to achieve GridView pagination". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report