Click here to Skip to main content
15,884,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i press a save button the record is saved into database and accordingly this data is shown in grid view. but when this data is shown in grid view the newly inserted record is displayed on the last row of the gridview. i want to display this record on the first row of gridview.
please help me.
Posted

if you post the code would help? but in your query to load the data base sort it base on creation time or identity column to have the latest one on the top. If there are multiple data inserts at the same times from different clients this solution does not ensure that the data inserted would be the very first one.

*Still post the code you are using to fill your dataset or datatable and the code you use to bind it to the gridview then we can give you a more relevant solution
 
Share this answer
 
You need sort the records in database or in datasource(in c#).

Example:

Using Query
SQL
SELECT * FROM TblEmp ORDER EmpID --It will display the sorted records by EmpID
SELECT * FROM TblEmp ORDER JoiningDate --It will display the sorted records by EmpID


BTW use ASC/DESC based on your requirement(loading records either in Ascending or Descending).

Using Datasource
C#
DataView dataView = new DataView(dTable);
dataView.Sort = " EmpID DESC";--It will display the sorted records by EmpID
GridView1.DataSource = dataView;
GridView1.DataBind();
 
Share this answer
 
Select * from TBL1 ORDER BY CreatedDate
 
Share this answer
 
u can do like this

C++
select * from table1 ORDER BY CreatedDate DESC
 
Share this answer
 
try this

 select * from Employee order by (empid)desc 

//EmpId is Primary key and identity column
 
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