Display Data with Sorting on fields .

 

1. Create a new page and save it as gridviewsorted.aspx

2. Drag the gridview from the data asp.net controls onto the page, You will see:

 

column viewgrid view

3. Select new data source from the drop down choose data source>  You will see:

data source dialog box

4. Select access Database and Click Ok, you will see:

Browse to Database

 

5. Type in the database name if in the root of the web site, or type in the folder/database name or browse and select the database and click next. .  In this example I will be using northwind.mdb.  You will see:

select table or view

6. In this view first select the table or view(query) that you want to use. Then select the fields from the table/view that you want to display. In this example I will select the employee table and the fields EmployeeId. Lasname, firstname, title, and hiredate by putting a check mark in the field I want to display.  You will see:

configure data source employee table

 

7. Now click order by:  You will see:

Sort Order

8.  Select Lastname in the sort by field, Select Firstname in the then by field you will see:

Order by clause

 

8. Click Ok you will see:

order by clause

9. Click Next:  you will see:

 

10. At this point when you view the page in browser the records will be sorted by last name and then first name.

11. To allow the user to sort on all of the fields selected.  Select the grid view and then grid view task.  You will see:

Grid view task

12. Put a check mark in the enable sorting.

13. Save the page and display in browser.  You will see:

 

sorted grid view

14. You can now click on the column heading to sort that column.  You can only sort one column at a time.