Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am stuck in a part to sort the data in a gridview in asp.net.I am using visual studio 2010 i want to take the content of the gridview and place it into the a new datatable so that i can sort the new datatable and make it a new source for the gridview.

i tried as

C#
dataTable forSortTable= GridView1.DataSource as DataTable;


but it didn't work for me
the forSortTable is always getting a null value.
Can anyone help me with this.
Thank you,
Arpan
Posted
Updated 18-Mar-12 4:48am
v3

1 solution

And it's not going to work.

Make it easy on yourself and stop trying to make a sqaure peg fit in a round hole.

You've done this backwards. Create the datatable first, then bind the grid to it. Then all of your entries will end up in the datatable without you having to do anything!
 
Share this answer
 
Comments
amsainju 18-Mar-12 11:21am    
Actually my idea was to sort a paged gridview. for an example my table ins tblForum with topicName and NumberofComment as an attribute. and with 26 records in the table and i have pagged the gridview to show only 5 records in one page.
suppose my first page displays topic name from a to e and there are records of topicname from a to z in the table. now if i click topicName the sorting should occur in e to a not in the form z to v in the first page. In summary i want to sort only the content of the page that is displayed. I hope i made my problem more clear. thank you for your reply

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