Here, we store the value of Sort Expression property into a Veiw State variable called sortexpression. Finally, we call Bind Grid() method which will bind sorted version of the Data View with the grid.
We need to access this variable from Bind Grid() method so that our sorting will work correctly under all the circumstances. The following figure shows the Grid View after implementing sorting.
The method essentially binds the Grid View with a Data View.
The Data View supplies all the records from the Employees table.
The Sorting event allows you to cancel the operation also.
The Sorting event handler receives an event argument of type Grid View Sort Event Args.
Interestingly if I look at the view source on my page when it is in edit state none of my controls appear just a table of values that would be held in the controls - is this normal?
They are: The former event is raised before the current page changes and the later is raised after the page has changed. Write the following code in the Page Index Changing event of the Grid View.The Sort Direction property specifies the direction of sorting i.e. This property is not of much when you are sorting the grid on your own.However, when coupled with data source controls the Grid View can toggle the sorting direction automatically for you and you can get/set the direction using this property.In order to develop a test web form create a new web site in VS. Set various properties of the Bound Fields as shown in the following table: Here, we call Bind Grid() method if the web form is being served as a result of first request.The Bind Grid() method is our own function that we will create later on.