ObjectDataSource.SortParameterName Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il nome dell'oggetto business utilizzato dal SelectMethod parametro per specificare un'espressione di ordinamento per il supporto dell'ordinamento dell'origine dati.
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
Valore della proprietà
Nome del parametro del metodo utilizzato per indicare il parametro utilizzato per ordinare i dati. Il valore predefinito è una stringa vuota.
Esempio
Questa sezione contiene due esempi di codice. Il primo esempio di codice illustra come implementare un tipo che supporta l'ordinamento. Il secondo esempio di codice illustra come implementare un'espressione di ordinamento.
Nell'esempio di codice seguente viene illustrato come implementare un tipo che supporta l'ordinamento. L'oggetto SelectMethod della SortingData classe accetta un parametro , sortExpression. La stringa passata a SelectMethod viene utilizzata per la Sort proprietà dell'oggetto DataView restituito da 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
Nell'esempio di codice seguente viene illustrato come implementare un'espressione di ordinamento. Il codice nella pagina Web crea un'istanza del ObjectDataSource controllo . La TypeName proprietà è impostata su SortingData e la SortParameterName proprietà è impostata su sortExpression. La AllowSorting proprietà del GridView controllo è impostata su true. Quando l'utente fa clic sul pulsante Ordina , il nome Name del campo o Number, viene passato al SelectMethod parametro di ordinamento.
<%--<%@ 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>
Commenti
La SortParameterName proprietà viene utilizzata per supportare l'ordinamento delle origini dati. Quando una SortExpression proprietà viene impostata sull'oggetto DataSourceSelectArguments e passata al Select metodo , il SortParameterName valore identifica il nome del parametro del metodo dell'oggetto SelectMethod business in base al quale vengono ordinati i dati.
Se l'oggetto ObjectDataSource è associato a un controllo associato a dati, i valori passati a questo parametro assumono la forma di valori di campo delimitati da virgole seguiti da "ASC" o "DESC". Ad esempio, il valore di un ordinamento crescente su Name sarà "Name ASC".
La SortParameterName proprietà delega alla SortParameterName proprietà dell'oggetto ObjectDataSourceView associato al ObjectDataSource controllo .