ObjectDataSource.SortParameterName Propriété

Définition

Obtient ou définit le nom de l'objet métier utilisé par le paramètre SelectMethod pour spécifier une expression de tri pour la prise en charge du tri de la source de données.

public:
 property System::String ^ SortParameterName { System::String ^ get(); void set(System::String ^ value); };
public string SortParameterName { get; set; }
member this.SortParameterName : string with get, set
Public Property SortParameterName As String

Valeur de propriété

String

Nom du paramètre de la méthode utilisé pour indiquer le paramètre permettant de trier les données. La valeur par défaut est une chaîne vide.

Exemples

Cette section contient deux exemples de code. Le premier exemple de code montre comment implémenter un type qui prend en charge le tri. Le deuxième exemple de code montre comment implémenter une expression de tri.

L’exemple de code suivant montre comment implémenter un type qui prend en charge le tri. SortingData La SelectMethod classe prend un paramètre. sortExpression Chaîne passée à SelectMethod utilisée pour la Sort propriété de l’objet DataView retourné par SelectMethod.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS
{
    public class SortingData
    {
        public SortingData()
        {
        }

        private static DataTable table;

        private DataTable CreateData()
        {
            table = new DataTable();
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Number", typeof(int));
            table.Rows.Add(new object[] { "one", 1 });
            table.Rows.Add(new object[] { "two", 2 });
            table.Rows.Add(new object[] { "three", 3 });
            table.Rows.Add(new object[] { "four", 4 });
            return table;
        }

        public DataView SelectMethod(string sortExpression)
        {
            table ??= CreateData();

            DataView dv = new DataView(table);
            dv.Sort = sortExpression;
            return dv;
        }
    }
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Namespace Samples.AspNet.VB
    Public Class SortingData
        Public Sub New()

        End Sub

        Private Shared table As DataTable

        Private Function CreateData() As DataTable
            table = New DataTable()
            table.Columns.Add("Name", GetType(String))
            table.Columns.Add("Number", GetType(Integer))
            table.Rows.Add(New Object() {"one", 1})
            table.Rows.Add(New Object() {"two", 2})
            table.Rows.Add(New Object() {"three", 3})
            table.Rows.Add(New Object() {"four", 4})
            Return table
        End Function

        Public Function SelectMethod(ByVal sortExpression As String) As DataView
            If table Is Nothing Then
                table = CreateData()
            End If

            Dim dv As New DataView(table)
            dv.Sort = sortExpression
            Return dv
        End Function


    End Class
End Namespace

L’exemple de code suivant montre comment implémenter une expression de tri. Le code de la page Web crée une instance du ObjectDataSource contrôle. La TypeName propriété est définie sur SortingData et la SortParameterName propriété est définie sur sortExpression. La AllowSorting propriété du GridView contrôle est définie sur true. Lorsque l’utilisateur clique sur le bouton Trier , le nom Name du champ ou Number, est passé SelectMethod au paramètre de tri.

<%--<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
--%><%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" 
            runat="server" 
            DataSourceID="ObjectDataSource1"
            AllowSorting="True">
        </asp:GridView>
        <asp:ObjectDataSource 
            ID="ObjectDataSource1" 
            runat="server" 
            SelectMethod="SelectMethod" 
            TypeName="Samples.AspNet.CS.SortingData" 
            SortParameterName="sortExpression">
        </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" 
            runat="server" 
            DataSourceID="ObjectDataSource1"
            AllowSorting="True">
        </asp:GridView>
        <asp:ObjectDataSource 
            ID="ObjectDataSource1" 
            runat="server" 
            SelectMethod="SelectMethod" 
            TypeName="Samples.AspNet.VB.SortingData" 
            SortParameterName="sortExpression">
        </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>

Remarques

La SortParameterName propriété est utilisée pour prendre en charge le tri de source de données. Lorsqu’une SortExpression propriété est définie sur l’objet DataSourceSelectArguments et transmise à la Select méthode, la SortParameterName valeur identifie le nom du paramètre de la SelectMethod méthode objet métier selon laquelle les données sont triées.

Si le ObjectDataSource contrôle lié aux données est associé, les valeurs transmises à ce paramètre prennent la forme de valeurs de champ séparées par des virgules suivies ou "ASC" "DESC". Par exemple, la valeur d’un tri Name croissant est "Name ASC".

La SortParameterName propriété délégué à la SortParameterName propriété de l’objet ObjectDataSourceView associé au ObjectDataSource contrôle.

S’applique à

Voir aussi