tags:

views:

38

answers:

1

how to use sort a data grid view even when its datasource is set

A: 

Sorting

Data in a grid is commonly sorted by clicking the header of the column to sort. Sorting in a DataGrid can be enabled by setting AllowSorting to true. When enabled, the grid renders LinkButton controls in the header for each column. When the button is clicked, the grid's SortCommand event is thrown. It's up to the programmer to handle this event in the code. Because DataGrid always displays the data in the same order it occurs in the data source, the typical logic sorts the data source, and then rebinds the data to the grid.

Collapse

//AllowSorting="True" //OnSorting="GridView2_Sorting" //SortExpression="name"

protected void GridView2_Sorting(object sender, GridViewSortEventArgs e) { //to check whether to display in ascending order or descending order if (e.SortExpression.Trim() == this.SortField) this.SortDirection = (this.SortDirection == "D" ? "A" : "D"); else this.SortDirection = "A"; this.SortField = e.SortExpression; TempTable(); }

Sheetal Inani