ObjectDataSource.SortParameterName 속성

정의

SelectMethod 매개 변수에서 데이터 소스 정렬을 지원하기 위해 정렬 식을 지정하는 데 사용하는 비즈니스 개체의 이름을 가져오거나 설정합니다.

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

속성 값

String

데이터 정렬에 사용되는 매개 변수를 나타내는 데 사용되는 메서드 매개 변수의 이름입니다. 기본값은 빈 문자열입니다.

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 코드 예제에는 정렬을 지 원하는 형식을 구현 하는 방법을 보여 줍니다. 두 번째 코드 예제에는 정렬 식을 구현 하는 방법을 보여 줍니다.

다음 코드 예제에는 정렬을 지 원하는 형식을 구현 하는 방법을 보여 줍니다. 합니다 SelectMethod 의 합니다 SortingData 매개 변수를 사용 하는 클래스가 sortExpression합니다. 에 전달 되는 문자열 SelectMethod 에 사용 되는 Sort 의 속성을 DataView 에서 반환 되는 개체 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

다음 코드 예제에는 정렬 식을 구현 하는 방법을 보여 줍니다. 인스턴스를 만들고 웹 페이지의 코드는 ObjectDataSource 제어 합니다. TypeName 속성이로 설정 되어 SortingData 하며 SortParameterName 속성이 sortExpression. 합니다 AllowSorting 의 속성을 GridView 로 설정 되어 true입니다. 클릭할 때 합니다 정렬 단추, 필드 이름을 Name 또는 Number, 전달 됩니다 SelectMethod 정렬 매개 변수에서.

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

설명

SortParameterName 속성은 데이터 소스 정렬을 지원 하기 위해 사용 합니다. 경우는 SortExpression 속성이 설정 되어를 DataSourceSelectArguments 개체를 전달할를 Select 메서드를를 SortParameterName 값의 매개 변수 이름을 식별는 SelectMethod 기준인 데이터 정렬 하는 비즈니스 개체 메서드.

경우는 ObjectDataSource 뒤에 형식으로 쉼표로 구분 된 필드 값이 매개 변수 사용에 전달 되는 값을 데이터 바인딩된 컨트롤과 관련이 "ASC" 또는 "DESC"합니다. 예를 들어, 값에 오름차순 정렬 Name"Name ASC"입니다.

SortParameterName 에 위임 하는 속성을 SortParameterName 의 속성을 ObjectDataSourceView 개체와 연결 된는 ObjectDataSource 컨트롤.

적용 대상

추가 정보