How to get the page from a row of a table, using page?

1

Suppose I have a table that shows 5 rows or records, with a fixed total of 12 records, that makes it have three pages so that one can page. But for example if I want to choose row 8, I need to get the page in which it is and save that value, that is, calculate and get the value of the page that is equal to "2". I would like to know how I could get that value 2, which is the page where the selected row is located.

Any idea how to do it, would I have to use any division of the row selected by the number of rows to show? I'm doing it in C #, but it does not matter the language, since it matters the algorithm

    
asked by Danilo 25.12.2016 в 18:30
source

1 answer

3

Simply get the rest of the entire division of the record you want, between the number of records per page, and add one if you want the first element of the index to be 1, if you do not treat it as if the first element of the index is 0. (Which is what you would use in an array)

For example, the No 8 record:

8 / 5 = 1,6  --> El resto de la división entera es 1 + 1 = 2

For item 12:

12 / 5 = 2,4 --> El resto de la división entera es 2 + 1 = 3
    
answered by 25.12.2016 / 22:02
source