how to get the value of the last row in a gridview [Resolved]

Posted by Jerome under ASP.NET on 3/23/2012 | Points: 10 | Views : 27737 | Status : [Member] | Replies : 9
i have a gridview and i want to get the value of the last row in the last three columns..




Responses

Posted by: Hmanjarawala on: 3/23/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi try this,

Hi,
If you want to fetch data from footer Raw then try this:

GridViewRow row = GridView1.FooterRow;
vr val1 = ((Label)row.FindControl("label1")).Text;
vr val2 = ((Label)row.FindControl("label2")).Text;
vr val3 = ((Label)row.FindControl("label3")).Text;


Or Fetch last row:

GridViewRow row = GridView1.Rows[GridView1.Rows.Count-1];
vr val1 = ((Label)row.FindControl("label1")).Text;
vr val2 = ((Label)row.FindControl("label2")).Text;
vr val3 = ((Label)row.FindControl("label3")).Text;


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/23/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,
If you want to fetch data from footer Raw then try this:
GridViewRow row = GridView1.FooterRow;


Or Fetch last row:
GridViewRow row = GridView1.Rows[GridView1.Rows.Count-1];


And then fetch columns value from this row

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jerome on: 3/23/2012 [Member] Starter | Points: 25

Up
0
Down
i have 7 columbs in my gridview and i want to get the last three coulumb values in the last row...how could i do this?...pls show me how...
thanks a lot!...

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/23/2012 [Member] Silver | Points: 25

Up
0
Down
Can Refer to this as well.
http://www.codeproject.com/Questions/136311/hightlight-last-record-in-grid-view

Thanks,
Sanjay

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/23/2012 [Member] Silver | Points: 25

Up
0
Down
Jerome ,
Do you want last 3-columns last row data in footer?

Thanks,
Sanjay

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jerome on: 3/23/2012 [Member] Starter | Points: 25

Up
0
Down
sanjay,

yes,i want to have the value of that coulumns in the last row

thanks,
jerome

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/23/2012 [Member] Silver | Points: 25

Up
0
Down
What Himanshu mentioned is correct
Create template field in those 3-column's footer row and the read the data of last row of those 3 columns and set the values in required found controls.
Thats it.


Thanks,
Sanjay

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jerome on: 3/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi Himanshu,

i already tried your code but it doesnt work..im using visual studio 8.

GridViewRow row = GridView1.Rows[GridView1.Rows.Count-1]; it gets error here,.."GridViewRow is a type and cannot be used as an expression"

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jerome on: 3/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi Himanshu,

your code logic really helped me...thanks a lot.I only got error on the sentax but I already fix it...


cheers,

jerome

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response