Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can I get the last row's data from a grid view without using loop. Please help me.
Posted
Updated 2-Jun-13 17:09pm
v2

1 solution

If you want to fetch data from footer Row then try...
C#
GridViewRow row = GridView1.FooterRow;

// Any column value on row.
vr val1 = ((Label)row.FindControl("label1")).Text;

Or just the last row...
C#
GridViewRow row = GridView1.Rows[GridView1.Rows.Count-1];

// Any column value on row.
vr val1 = ((Label)row.FindControl("label1")).Text;
 
Share this answer
 
Comments
Sumon562 3-Jun-13 2:09am    
Thank you Mr. Tadit Dash for your kind response. Actually I do not use any control in the gridview. I just want last Row;s first column's data. I think you can help me now.
Yes, then just do like below...

GridViewRow row = GridView1.Rows[GridView1.Rows.Count - 1];
string val = row.Cells[0].Text;
Sumon562 3-Jun-13 2:11am    
I am waiting for your answer.
Check the above comment.
Sumon562 3-Jun-13 2:33am    
I have written the following codes :
GridViewRow row = grdEdit.Rows[grdEdit.Rows.Count - 1];
string val = row.Cells[0].Text;
dtpMaintenceEnd.Text = val.ToString();
But it brings empty value;

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