ASP.NET - 试图实现SortParameterName财产的SqlDataSource [英] ASP.NET - Trying to implement SortParameterName property to SqlDataSource

查看:162
本文介绍了ASP.NET - 试图实现SortParameterName财产的SqlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个GridView的和中继器绑定到使用存储过程SqlDataSources。我想实现排序功能到其中的一些,但我有一个很难找到具体的指令和/或需要如何在SqlDataSource端生成ORDER BY的需要的例子。特别是,我不明白有在SqlDataSource的一个SortParameterName属性点,如果它所做的是手动连接到一个ORDER BY子句中的存储过程。为什么它定义为这样的,如果它是在SelectParameters列表像任何其他只是另一个参数,但恰好连接到ORDER BY子句?当我运行低于code为例,据我所知有指定的参数太多(当然,额外的SortParams参数)。我真的需要改变我的存储过程,并添加ORDER BY @SortParams条款对现有查询的末尾,使这项工作?我觉得我失去了一些东西。

I have several Gridviews and Repeaters bound to SqlDataSources using stored procedures. I am trying to implement sorting functionality into some of these but am having a hard time finding concrete instructions and/or examples of what is required on the SqlDataSource side to generate the ORDER BY's needed. Particularly, I do not understand the point of having a SortParameterName property in the SqlDataSource if all it does is manually connect to an ORDER BY clause in the stored procedure. Why define it as such if it is just another parameter in the SelectParameters list like any other, but just so happens to be connected to the ORDER BY clause? When I run the code example below, I am told there are too many arguments specified (obviously, the extra SortParams argument). Do I really need to alter my stored procedures and add "ORDER BY @SortParams" clauses to the end of the existing queries to make this work? I feel like I am missing something.

    SqlDataSourceInLine.SelectParameters.Clear()
    SqlDataSourceInLine.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
    SqlDataSourceInLine.SelectCommand = "ApproverGetApproved"
    SqlDataSourceInLine.SelectParameters.Add("CompanyID", ConfigurationManager.AppSettings("Temp_CompanyID"))
    SqlDataSourceInLine.SelectParameters.Add("SortParams", "EmpName DESC")
    SqlDataSourceInLine.DataSourceMode = SqlDataSourceMode.DataSet
    SqlDataSourceInLine.SortParameterName = "SortParams"
    Dim dv As DataView = SqlDataSourceInLine.Select(DataSourceSelectArguments.Empty

任何澄清将AP preciated!

Any clarification would be appreciated!

推荐答案

我从来没有使用 SortParamter 在过去,但我收集<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.sortparametername.aspx\"相对=nofollow>从文档是,这个参数的目的是为了让你得到的结果进行排序的方式,你希望他们的的情况下,存储过程没有做了。除此之外,你并不需要使用它的任何东西。一个GridView的数据源的类型的SqlDataSource已经实现了整理开箱即用的。你只需要在 AllowSorting 属性设置为 SORTEX pression 的每一列。

I've never used the SortParamter in the past, but what I gather from the documentation is that the purpose of this parameter is to allow you to get the results sorted in the way you want them in case the stored procedure does not do it already. Other than that, you don't need to use it for anything. A GridView whose datasource is of type SqlDataSource already implements sorting out of the box. You simply need to set the AllowSorting property to True and the SortExpression on every column.

例如:

 <asp:GridView ID=" productsGridView" Runat="server" 
     DataSourceID="SqlproductDataSource" AutoGenerateColumns="False"
        AllowSorting="True" >
        <Columns>
            <asp:BoundField HeaderText="Product" 
              DataField="ProductName" SortExpression="ProductName">
            </asp:BoundField>
  ...

这篇关于ASP.NET - 试图实现SortParameterName财产的SqlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆