Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
how to display last record of datatable in gridview

pls let me know clearly as i am beginner.
Posted
Comments
surender.m 28-Jul-11 2:45am    
Why you need only last record?

If you need only the last row, then change your query to fill the datatable with only the last row of the table. For that, your query must contain 'top 1' and 'order by .. desc'. You can refer to How to get last record in dataset table in asp.net[^]
 
Share this answer
 
VB
Dim dr As DataRow = dtTable.Rows(dtTable.Rows.Count - 1)
            grd1.DataSource = dr
            grd1.DataBind()


Here grd1 is gridview and dtTable is dataTable created from database.

hope this helps you.
 
Share this answer
 
If you have the datatable rows count , you can simply get the last record either by iterating through the rows till the count-1 or else you can directly get the datarow of count-1.

Hope this may help you.
 
Share this answer
 

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