hi..

im retriving some data from a database to a dataset...i want to show the data in a gridview..but my problem is, i want data to be shown in last to first format. i mean, if the dataset contains, A as first record & z as last record, then the gridview should show the list with Z as the first record and A as the last record.

i don want to sort the data in ascending or descending format. is there any way to show the data in tht fashion? do i need to put some keywords in the query or is ther any other method?

thanks,

Yes you can change the order of rows using Linq Dataset,

DataTable dt = new DataTable("Test");
        dt.Columns.Add("No", typeof(int));
        dt.Columns.Add("Name");
        dt.Rows.Add(1, "R");
        dt.Rows.Add(5, "A");
        dt.Rows.Add(4, "W");
        dt.Rows.Add(2, "C");

        dt.AcceptChanges();
        var t = (from rec in dt.AsEnumerable() select rec).Reverse();
        dt = t.CopyToDataTable();
        GridView1.DataSource = dt;
        GridView1.DataBind();

hi adatapost ,
im working in VS 2005 n Linq relates to 2008 i guess..so i dont think it will helpful...

n shibbard,
the order by clause will SORT the data in Asc or Desc order. i dont want to sort a particular column, i want to show it like Stack..last in first out..last record should be displayed as the first record.

hope for a response soon..

Thanks..

Ok then just have a number column (e.g. ID) - with it set as Identity Insert on (see http://www.w3schools.com/Sql/sql_autoincrement.asp) or just use SQL server manager to set it.

Then use ORDER BY ID Desc. Last record will be first and sorted in the order that rows where added.

Just collect the data as a generic list. You can sort it through the following code.

objList.Sort((x, y) => (x.columnname.CompareTo(y.columnname)));

With regards
Nishithraj Narayanan
<URL SNIPPED>

hey hi..
it was really a simple trick n i wasted gr8 time on the same...
im already using a auto incremented id's in my DB..n i sorted it and its done..

Thanks alot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.