Author: azamsharp translation: sharpcn Description: In this small code snippet, I will demonstrate how to use DataGrid bound column [] to another method of sorting. Remember, there are many ways to sort [Items] of [DataGrid], which is only one of them. Add a binding column: First, add some binding columns to your [DataGrid] with [Properties Builder]. Because this is a medium-level article, you should know how to do this. After you add a binding column, give [DataGrid] a data source and populate some data. Two ways to sort DataGrid: Ok, you can start now. [DataGrid] should be filled with some data. Set allowsorting = "true" in the properties window of [DataGrid]. Ok, you can sort the DataGrid. What to do now is to add a sorted actual code for [DataGrid]. DataGrid sort code: No matter when, as long as the header is clicked, the SortCommand event will be triggered. Therefore, we put the following code in the SortCommand event processor. private void Sort_DataGrid (object sender, System.Web.UI.WebControls.DataGridSortCommandEventAgrs e) {// Do not place stored procedure SqlCommand myCommand = new SqlCommand ( "SELECT * FROM Categories", myConnection) in this command; myCommand.CommandType = CommandType .Text; sqldataadapter myadapter = new sqldataadapter (MyCommand); DataSet DS = new dataset (); myadapter.fill (DS, "categories"); DataView DV = New DataView (DS.Tables ["categories"]); if (( NumberDiv% 2) == 0) DV.Sort = E.Sortexpression " " ASC "; else Dv.Sort = E.Sortexpression " " " DESC "; Numberdiv ; mydatagrid.dataSource = DV; mydatagrid.databind (); The core of this example is a [DataView] object with the [Sortexpression] property, she describes the name of the column column. Finally, just assign a [DataSource] to [DataView] and bind [DataGrid] on the page.