首页 / 网页编程 / ASP.NET / ASP.NET 2.0数据教程之四十五:DataList和Repeater数据排序(三)
        
            ASP.NET 2.0数据教程之四十五:DataList和Repeater数据排序(三)2010-08-11 翻译:cnblogs 有些伤感返回“”第七步: 在自定义分页的Repeater 里添加排序功能现在已经完成了自 定义分页,我们再来添加排序功能。ProductsBLL类的 GetProductsPagedAndSorted方法和GetProductsPaged一样有startRowIndex 和 maximumRows 参数,不一样的是它还多了一个sortExpression 参数。在 SortingWithCustomPaging.aspx里使用GetProductsPagedAndSorted方法我们需要 :将ObjectDataSource的SelectMethod属性从GetProductsPaged改为 GetProductsPagedAndSorted。为ObjectDataSource的SelectParameters 参数集合增加一个sortExpression Parameter。创建一个私有的属性用来 在postback过程中通过view state存储SortExpression。修改 ObjectDataSource的Selecting event handler将ObjectDataSource的 sortExpression 参数值赋为SortExpression 属性(3中创建的)。创建 排序界面。首先修改ObjectDataSource的SelectMethod属性并添加 sortExpression 参数。确定sortExpression 的类型是String。完成这些后 ObjectDataSource的声明标记看起来应该和下面差不多:ASP.NET<asp:ObjectDataSource ID="ProductsDataSource" runat="server"
   OldValuesParameterFormatString="original_{0}" TypeName="ProductsBLL"
   SelectMethod="GetProductsPagedAndSorted"
   OnSelecting="ProductsDataSource_Selecting">
   <SelectParameters>
    <asp:Parameter Name="sortExpression" Type="String" />
     <asp:Parameter Name="startRowIndex" Type="Int32" />
    <asp:Parameter Name="maximumRows" Type="Int32" />
   </SelectParameters>
</asp:ObjectDataSource>Next, we need a page-level SortExpression property whose value is serialized to view state. If no sort expression value has been set, use “ProductName” as the default: