如何在ASP.NET里用DataView来达到DataGrid控件里的Column Sorting效果。
(華版)
这幾天一直在钻研ADO.NET对象和DataGrid控件的基本功能,以下是一点点收获并何大家分享分享。
一般在WinForm里的DataGrid控件都是有提供Column Sorting的功能,但是在WebForm里就没了。。。其实我们可以用ADO.NET对象里的DataView来达到相同的效果;只是需要写多一点点的代码而已。另外,我们也先要把DataGrid控件的AllowSorting属性值改去True。
在Code Behind Page里,我们只需要在DataGrid1_SortCommand事件里读取所选的Column的名字;然后就如平常从数据苦里读取资料一样,只是将DataSet里的数据转到一个新的DataView对象,并把DataView.Sort属性值改为之前所得到的Column名字。那么,最后一步当然就是把DataView bind到DataGrid控件里。。。这样就大功告成了!
All the posts in this blog are provided "AS IS" with no warranties, and confer no rights. Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 2.5 China Mainland License.
浙公网安备 33010602011771号