Mike Cat (Mikecat)
From: Old cat の Ide
Oh, this didn't write the meaning of the article. I saw the article, HBZXF. I decided to write the usual things and share it! Have omissions, please advise!
It is convenient to use the DataGrid control in ASP.NET. But we can only sort in single item! If we need to be routing, then you need to add some code to control, let me explain this process in detail.
First we need to set the properties of the DataGird control to allowsorting = "true", and the sequence of sequence needs to be set to make sorted expression EG: sortexpression = "kmdm". Set these, we enter the code file to write an event in response to sort.
First add the following code to the Page_Load time:
If (! ispostback) {if (this.kjkm_dg.attributes ["sortexpression"] == null) // Here KJKM_DG is DATAGRID ID {this.kjkm_dg.attributes ["sortexpression"] = "kmdm"; // Here you give DataGrid Add a sorting attribute, and the default sorting expression is KMDM; kjkm_dg.attributes ["sortdirection"] = "ASC"; // Here you add a sorting direction attribute to DataGrid, and default is ascending paragraphs;} mikecatbind (); // Binding function, here is introduced}
protected void mikecatbind () {string sqlStr = "select * from zc_kjkm"; DataView dv = new DataView (); string SortExpression = kjkm_dg.Attributes [ "SortExpression"]; string SortDirection = kjkm_dg.Attributes [ "SortDirection"]; dv = US.bind (Sqlstr) .Tables [0] .defaultView; // From Web Service DataSet, here will be able to; dv.sort = sortexpression " sortdirection; // Specify the sort method of the view; kjkm_dg.datasource = DV; // Specify data source kjkm_dg.database (); // data binding
}
After the above settings we entered the important link, the preparation of the event:
private void kjkm_dg_SortCommand (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) {string SortExpression = e.SortExpression.ToString (); // get the current sort expression string SortDirection = "ASC"; // variable sort direction Assignment IF (sortexpression == kjkm_dg.attributes ["sortexpression"]) // If you are sequence {sortdirection = (kjkm_dg.attributes ["sortdirection"]. TOSTRING () == Sortdirection? "DESC": "ASC "); // get the next sort status} kjkm_dg.attributes [" sortexpression "] = sortexpression; kjkm_dg.attributes [" sortdirection "] = sortdirection; mikecatbind ();
Ok, try see if it can be arranged in front.