|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Proprietà ObjectDataSource.EnableCaching
Spazio dei nomi: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
| Eccezione | Condizione |
|---|---|
| NotSupportedException |
<form id="form1" runat="server"> <div> <asp:objectdatasource ID="ObjectDataSource1" runat="server" SelectMethod="GetFullNamesAndIDs" TypeName="Samples.AspNet.CS.EmployeeLogic" /> <p> <asp:dropdownlist ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1" DataTextField="FullName" DataValueField="EmployeeID" AutoPostBack="True" AppendDataBoundItems="true"> <asp:ListItem Text="Select One" Value=""></asp:ListItem> </asp:dropdownlist> </p> <asp:objectdatasource ID="ObjectDataSource2" runat="server" SelectMethod="GetEmployee" TypeName="Samples.AspNet.CS.EmployeeLogic" EnableCaching="true" CacheKeyDependency="EmployeeDetails" > <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="-1" Name="empID" /> </SelectParameters> </asp:objectdatasource> <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="ObjectDataSource2" AutoGenerateRows="false"> <Fields> <asp:BoundField HeaderText="Address" DataField="Address" /> <asp:BoundField HeaderText="City" DataField="City" /> <asp:BoundField HeaderText="Postal Code" DataField="PostalCode" /> </Fields> </asp:DetailsView> <asp:Button ID="Button1" runat="server" Text="Check for latest data" OnClick="Button1_Click" /> </div> </form>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Cache[ObjectDataSource2.CacheKeyDependency] = "CacheExample"; } } protected void Button1_Click(object sender, EventArgs e) { Cache.Remove(ObjectDataSource2.CacheKeyDependency); Cache[ObjectDataSource2.CacheKeyDependency] = "CacheExample"; DetailsView1.DataBind(); }
public class EmployeeLogic { public static Array GetFullNamesAndIDs() { NorthwindDataContext ndc = new NorthwindDataContext(); var employeeQuery = from e in ndc.Employees orderby e.LastName select new { FullName = e.FirstName + " " + e.LastName, EmployeeID = e.EmployeeID }; return employeeQuery.ToArray(); } public static Employee GetEmployee(int empID) { if (empID < 0) { return null; } else { NorthwindDataContext ndc = new NorthwindDataContext(); var employeeQuery = from e in ndc.Employees where e.EmployeeID == empID select e; return employeeQuery.Single(); } } public static void UpdateEmployeeAddress(Employee originalEmployee, string address, string city, string postalcode) { NorthwindDataContext ndc = new NorthwindDataContext(); ndc.Employees.Attach(originalEmployee, false); originalEmployee.Address = address; originalEmployee.City = city; originalEmployee.PostalCode = postalcode; ndc.SubmitChanges(); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.