0

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,

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by love_dude1984
0

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();
0

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..

0

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>

Edited by peter_budo: Keep It On The Post - Do not manually post &quot;fake&quot; signatures in your posts.

0

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..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.