Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi am having a grid in my aspx page, and set "Allow paging= true"

Now i want to get the last row record of the last page.

i tried the following code to get the 1st row record,

C#
GridViewRow FirstRow = gdvData.Rows[0];//getting 1st row of 1st page working fine

GridViewRow LastRow = gdvData.Rows[gdvData.Rows.Count - 1];//getting last row of last page is not works


Ex. grid contains 6 pages, i want to retrieve last record of the 6th page.

The above code retrieve the last record of the 1st page but here i want last row of 6th page only.

any idea?
Posted

1 solution

First you need to unpage your grid view.
Try this:
 this.gdvData.AllowPaging = false;
 this.gdvData.AllowSorting = false;
 this.gdvData.EditIndex = -1;
// Let's bind data to GridView
 this.RefreshGrid();
GridViewRow FirstRow = gdvData.Rows[0];//getting 1st row of 1st page working fine
                
GridViewRow LastRow = gdvData.Rows[gdvData.Rows.Count - 1];//getting last row of last page is not works
            this.gdvData.AllowPaging = true;
            this.gdvData.AllowSorting = true;
            this.gdvData.EditIndex = -1;


Fist you will un-page your gridview, get the last row and then page it again.
I hope this will help you!
 
Share this answer
 
v2
Comments
R. Ramprakash 4-Oct-13 6:04am    
i tried the above its not working..
Diana Tsax 4-Oct-13 6:09am    
could you try to put this code :
this.gdvData.AllowPaging = false;
this.gdvData.AllowSorting = false;
this.gdvData.EditIndex = -1;
Before this
GridViewRow FirstRow = gdvData.Rows[0];//getting 1st row of 1st page working fine
R. Ramprakash 4-Oct-13 6:25am    
i want to find the last row of the last page and make particular column value disable..for that am trying this but couldn't get the idea..

i tried your code but not getting the correct output..
Diana Tsax 4-Oct-13 6:34am    
Sorry my mistake i miss to bind data before gettinf first and last row.
do it like this:
this.gdvData.AllowPaging = false;
this.gdvData.AllowSorting = false;
this.gdvData.EditIndex = -1;
// Let's bind data to GridView
this.RefreshGrid();
and then
GridViewRow FirstRow = gdvData.Rows[0];//getting 1st row of 1st page working fine
GridViewRow LastRow = gdvData.Rows[gdvData.Rows.Count - 1];//getting last row of last page is not works
this.gdvData.AllowPaging = true;
this.gdvData.AllowSorting = true;
this.gdvData.EditIndex = -1;
i try it and it works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900