GridView.SortDirection 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
정렬하고 있는 열의 정렬 방향을 가져옵니다.
public:
virtual property System::Web::UI::WebControls::SortDirection SortDirection { System::Web::UI::WebControls::SortDirection get(); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public virtual System.Web.UI.WebControls.SortDirection SortDirection { get; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.SortDirection : System.Web.UI.WebControls.SortDirection
Public Overridable ReadOnly Property SortDirection As SortDirection
속성 값
SortDirection 값 중 하나입니다. 기본값은 SortDirection.Ascending
입니다.
- 특성
예제
다음 예제에서는 프로그래밍 방식으로 컨트롤의 SortDirection 정렬 방향을 결정 하는 속성을 사용 하는 방법을 보여 줍니다 GridView .
<%@ 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">
void CustomersGridView_DataBound(Object sender, EventArgs e)
{
// Get the header row.
GridViewRow headerRow = CustomersGridView.HeaderRow;
// Get the footer row.
GridViewRow footerRow = CustomersGridView.FooterRow;
// Set the font color of the header and footer rows
// based on the sort direction.
switch (CustomersGridView.SortDirection)
{
case SortDirection.Ascending:
headerRow.ForeColor = System.Drawing.Color.Green;
footerRow.ForeColor = System.Drawing.Color.Green;
break;
case SortDirection.Descending:
headerRow.ForeColor = System.Drawing.Color.Red;
footerRow.ForeColor = System.Drawing.Color.Red;
break;
default:
headerRow.ForeColor = System.Drawing.Color.Black;
footerRow.ForeColor = System.Drawing.Color.Black;
break;
}
// Display the sort order in the footer row.
footerRow.Cells[0].Text = "Sort Order = " + CustomersGridView.SortDirection.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView HeaderRow and FooterRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView HeaderRow and FooterRow Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowsorting="true"
allowpaging="true"
showheader="true"
showfooter="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<headerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
<footerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
<%@ 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">
Sub CustomersGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
' Get the header row.
Dim headerRow As GridViewRow = CustomersGridView.HeaderRow
' Get the footer row.
Dim footerRow As GridViewRow = CustomersGridView.FooterRow
' Set the font color of the header and footer rows
' based on the sort direction.
Select Case CustomersGridView.SortDirection
Case SortDirection.Ascending
headerRow.ForeColor = System.Drawing.Color.Green
footerRow.ForeColor = System.Drawing.Color.Green
Case SortDirection.Descending
headerRow.ForeColor = System.Drawing.Color.Red
footerRow.ForeColor = System.Drawing.Color.Red
Case Else
headerRow.ForeColor = System.Drawing.Color.Black
footerRow.ForeColor = System.Drawing.Color.Black
End Select
' Display the sort order in the footer row.
footerRow.Cells(0).Text = "Sort Order = " & CustomersGridView.SortDirection.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView HeaderRow and FooterRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView HeaderRow and FooterRow Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
allowsorting="true"
allowpaging="true"
showheader="true"
showfooter="true"
ondatabound="CustomersGridView_DataBound"
runat="server">
<headerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
<footerstyle backcolor="LightCyan"
forecolor="MediumBlue"/>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
SortDirection 정렬할 열이 오름차순 또는 내림차순으로 정렬되는지 여부를 확인하려면 이 속성을 사용합니다.
참고
컨트롤에는 GridView 이 속성을 자동으로 설정하는 기본 제공 정렬 기능이 있습니다. 이 속성은 일반적으로 프로그래밍 방식으로 정렬 방향을 결정 해야 하거나 컨트롤에 사용자 지정 정렬 기능을 추가 하는 GridView 경우에 사용 됩니다.