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

.net how to implement GridView paging template

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

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!

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