Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 SortParameterName Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ObjectDataSource..::.SortParameterName Property

Gets or sets the name of the business object that the SelectMethod parameter used to specify a sort expression for data source sorting support.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Property SortParameterName As String
Visual Basic (Usage)
Dim instance As ObjectDataSource
Dim value As String

value = instance.SortParameterName

instance.SortParameterName = value
C#
public string SortParameterName { get; set; }
Visual C++
public:
property String^ SortParameterName {
    String^ get ();
    void set (String^ value);
}
JScript
public function get SortParameterName () : String
public function set SortParameterName (value : String)
ASP.NET
<asp:ObjectDataSource SortParameterName="String" />

Property Value

Type: System..::.String
The name of the method parameter used to indicate the parameter which is used to sort the data. The default is an empty string.

The SortParameterName property is used to support data source sorting. When a SortExpression property is set on the DataSourceSelectArguments object and passed to the Select method, the SortParameterName value identifies the parameter name of the SelectMethod business object method according to which the data is sorted.

If the ObjectDataSource is associated with a data-bound control, the values that are passed to this parameter take the form of comma-separated field values followed by "ASC" or "DESC". For example, the value for an ascending sort on Name would be "Name ASC".

The SortParameterName property delegates to the SortParameterName property of the ObjectDataSourceView object that is associated with the ObjectDataSource control.

This section contains two code examples. The first code example demonstrates how to implement a type that supports sorting. The second code example demonstrates how to implement a sort expression.

The following code example demonstrates how to implement a type that supports sorting. The SelectMethod of the SortingData class takes a parameter, sortExpression. The string that is passed to SelectMethod is used for the Sort property of the DataView object that is returned by SelectMethod.

Visual Basic
Imports System
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

C#
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)
        {
            if (table == null)
            {
                table = CreateData();
            }

            DataView dv = new DataView(table);
            dv.Sort = sortExpression;
            return dv;
        }

    }
}

The following code example demonstrates how to implement a sort expression. The code in the Web page creates an instance of the ObjectDataSource control. The TypeName property is set to SortingData and the SortParameterName property is set to sortExpression. The AllowSorting property of the GridView control is set to true. When the user clicks the Sort button, the field name, Name or Number, is passed to SelectMethod in the sort parameter.

Visual Basic
<%@ 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  >
<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>

C#
<%--<%@ 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  >
<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>

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker