|
Il presente articolo è stato tradotto manualmente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale.
|
Traduzione
Originale
|
Proprietà ObjectDataSourceView.FilterExpression
Assembly: System.Web (in System.Web.dll)
Valore proprietà
Tipo: System.String| Eccezione | Condizione |
|---|---|
| NotSupportedException |
Nota sulla sicurezza |
|---|
<%@ 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"> protected void ObjectDataSource1_Filtering(object sender, ObjectDataSourceFilteringEventArgs e) { if (Textbox1.Text == "") { e.ParameterValues.Clear(); e.ParameterValues.Add("FullName", "Nancy Davolio"); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ObjectDataSource - C# Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <p>Show all users with the following name.</p> <asp:textbox id="Textbox1" runat="server" text="Nancy Davolio" /> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" autogeneratecolumns="False"> <columns> <asp:boundfield headertext="ID" datafield="EmpID" /> <asp:boundfield headertext="Name" datafield="FullName" /> <asp:boundfield headertext="Street Address" datafield="Address" /> </columns> </asp:gridview> <!-- Security Note: The ObjectDataSource uses a FormParameter, Security Note: which does not perform validation of input from the client. --> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployeesAsDataSet" typename="Samples.AspNet.CS.EmployeeLogic" filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering"> <filterparameters> <asp:formparameter name="FullName" formfield="Textbox1" defaultvalue="Nancy Davolio" /> </filterparameters> </asp:objectdatasource> <p><asp:button id="Button1" runat="server" text="Search" /></p> </form> </body> </html>
La classe EmployeeLogic, vale a dire una classe che incapsula la logica business. La classe NorthwindEmployee, vale a dire una classe modello che contiene soltanto la funzionalità di base richiesta per caricare e mantenere i dati dal livello dati.
namespace Samples.AspNet.CS { using System; using System.Collections; using System.Data; using System.Web.UI.WebControls; // // EmployeeLogic is a stateless business object that encapsulates // the operations you can perform on a NorthwindEmployee object. // public class EmployeeLogic { // Returns a collection of NorthwindEmployee objects. public static ICollection GetAllEmployees () { ArrayList data = new ArrayList(); data.Add(new NorthwindEmployee(1,"Nancy","Davolio","507 - 20th Ave. E. Apt. 2A")); data.Add(new NorthwindEmployee(2,"Andrew","Fuller","908 W. Capital Way")); data.Add(new NorthwindEmployee(3,"Janet","Leverling","722 Moss Bay Blvd.")); data.Add(new NorthwindEmployee(4,"Margaret","Peacock","4110 Old Redmond Rd.")); data.Add(new NorthwindEmployee(5,"Steven","Buchanan","14 Garrett Hill")); data.Add(new NorthwindEmployee(6,"Michael","Suyama","Coventry House Miner Rd.")); data.Add(new NorthwindEmployee(7,"Robert","King","Edgeham Hollow Winchester Way")); return data; } public static NorthwindEmployee GetEmployee(object anID) { ArrayList data = GetAllEmployees() as ArrayList; int empID = Int32.Parse(anID.ToString()); return data[empID] as NorthwindEmployee; } // // To support basic filtering, the employees cannot // be returned as an array of objects, rather as a // DataSet of the raw data values. public static DataSet GetAllEmployeesAsDataSet () { ICollection employees = GetAllEmployees(); DataSet ds = new DataSet("Table"); // Create the schema of the DataTable. DataTable dt = new DataTable(); DataColumn dc; dc = new DataColumn("EmpID", typeof(int)); dt.Columns.Add(dc); dc = new DataColumn("FullName",typeof(string)); dt.Columns.Add(dc); dc = new DataColumn("Address", typeof(string)); dt.Columns.Add(dc); // Add rows to the DataTable. DataRow row; foreach (NorthwindEmployee ne in employees) { row = dt.NewRow(); row["EmpID"] = ne.EmpID; row["FullName"] = ne.FullName; row["Address"] = ne.Address; dt.Rows.Add(row); } // Add the complete DataTable to the DataSet. ds.Tables.Add(dt); return ds; } } public class NorthwindEmployee { public NorthwindEmployee (int anID, string aFirstName, string aLastName, string anAddress) { ID = anID; firstName = aFirstName; lastName = aLastName; address = anAddress; } private object ID; public string EmpID { get { return ID.ToString(); } } private string lastName; public string LastName { get { return lastName; } set { lastName = value; } } private string firstName; public string FirstName { get { return firstName; } set { firstName = value; } } public string FullName { get { return FirstName + " " + LastName; } } private string address; public string Address { get { return address; } set { address = value; } } } }
Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Nota sulla sicurezza