DynamicRouteExpression Classe
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 la chiave primaria dalle informazioni di routing per eseguire il filtro dei dati.
public ref class DynamicRouteExpression : System::Web::UI::WebControls::Expressions::DataSourceExpression
public class DynamicRouteExpression : System.Web.UI.WebControls.Expressions.DataSourceExpression
type DynamicRouteExpression = class
inherit DataSourceExpression
Public Class DynamicRouteExpression
Inherits DataSourceExpression
- Ereditarietà
Esempio
Nell'esempio seguente viene illustrato un modello di pagina di List.aspx personalizzato per la tabella Products. Usa la ColumnName proprietà per specificare la chiave esterna ProductCategory per filtrare le righe Products.
Nella pagina personalizzata List.aspx viene visualizzata una colonna contenente collegamenti delle categorie contenute nella colonna Chiave esterna ProductCategory. Quando l'utente fa clic su uno di questi collegamenti, nella pagina List.aspx vengono visualizzate solo le righe che contengono la categoria selezionata.
L'esempio richiede quanto segue:
- Sito Web Dynamic Data. Per altre informazioni, vedere Procedura dettagliata: Creazione di un nuovo sito Web di dati dinamici tramite scaffolding.
- Database di esempio AdventureWorksLT.
<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="List.aspx.cs" Inherits="List" %>
<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
<asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
<DataControls>
<asp:DataControlReference ControlID="GridView1" />
</DataControls>
</asp:DynamicDataManager>
<h2 class="DDSubHeader">Using DynamicRouteExpression with <%= table.DisplayName%> table</h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="DD">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />
<br /> <br />
<div class="DDFilter">
<asp:HyperLink runat="server" ID="ViewAllLink" Text="View All Categories" />
</div>
</div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit"
/> <asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
OnClientClick='return confirm("Are you sure you want to delete this item?");'
/> <asp:DynamicHyperLink runat="server" Text="Details" />
<!-- Create action link to filter items that
belong to the same category -->
<a ID="CategoryRouteID" runat="server"
href='<%# GetRouteInformation() %>'>
Filter By: <%# GetProductCategory() %>
</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="DDFooter"/>
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
<asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true" />
<asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
<asp:DynamicRouteExpression ColumnName="ProductCategory" />
</asp:QueryExtender>
<br />
<div class="DDBottomHyperLink">
<asp:DynamicHyperLink ID="InsertHyperLink" runat="server" Action="Insert"><img runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:DynamicHyperLink>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
<%@ Page Language="VB" MasterPageFile="~/Site.master" CodeFile="List.aspx.vb" Inherits="List" %>
<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
<asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
<DataControls>
<asp:DataControlReference ControlID="GridView1" />
</DataControls>
</asp:DynamicDataManager>
<h2 class="DDSubHeader"><%= table.DisplayName%></h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="DD">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
HeaderText="List of validation errors" CssClass="DDValidator" />
<asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />
</div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit"
/> <asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
OnClientClick='return confirm("Are you sure you want to delete this item?");'
/> <asp:DynamicHyperLink runat="server" Text="Details" />
<!-- Create action link to filter items that
belong to the same category -->
<a ID="CategoryRouteID" runat="server"
href='<%# GetRouteInformation() %>'>
Filter By: <%# GetProductCategory() %>
</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="DDFooter"/>
<PagerTemplate>
<asp:GridViewPager runat="server" />
</PagerTemplate>
<EmptyDataTemplate>
There are currently no items in this table.
</EmptyDataTemplate>
</asp:GridView>
<asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true" />
<!-- Set the foreign-key to use for filtering -->
<asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
<asp:DynamicRouteExpression ColumnName="ProductCategory" />
</asp:QueryExtender>
<br />
<div class="DDBottomHyperLink">
<asp:DynamicHyperLink ID="InsertHyperLink" runat="server" Action="Insert"><img runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:DynamicHyperLink>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
// Create route information based on the
// foreign-key specified in the
// DynamicRouteExpression page markup.
protected string GetRouteInformation()
{
// Retrieve the current data item.
var productItem = (Product)GetDataItem();
if (productItem != null)
{
RouteValueDictionary rvd = new RouteValueDictionary();
rvd.Add("ProductCategoryID", productItem.ProductCategoryID );
string routePath =
table.GetActionPath(PageAction.List, rvd);
return routePath;
}
return string.Empty;
}
// Get the name of the foreign-key category.
protected string GetProductCategory()
{
// Retrieves the current data item.
var productItem = (Product)GetDataItem();
if (productItem != null)
{
return productItem.ProductCategory.Name;
}
return string.Empty;
}
' Create route information based on the
' foreign-key specified in the
' DynamicRouteExpression page markup.
Protected Function GetRouteInformation() As String
' Retrieve the current data item.
Dim productItem = CType(GetDataItem(), Product)
If productItem IsNot Nothing Then
Dim rvd As New RouteValueDictionary()
rvd.Add("ProductCategoryID", productItem.ProductCategoryID)
Dim routePath As String = table.GetActionPath(PageAction.List, rvd)
Return routePath
End If
Return String.Empty
End Function
' Get the name of the foreign-key category.
Protected Function GetProductCategory() As String
' Retrieves the current data item.
Dim productItem = CType(GetDataItem(), Product)
If productItem IsNot Nothing Then
Return productItem.ProductCategory.Name
End If
Return String.Empty
End Function
Commenti
La DynamicRouteExpression classe viene usata con il QueryExtender controllo nel markup della pagina. La DynamicRouteExpression classe ottiene la chiave primaria dalle informazioni di routing contenute in una richiesta Web. Il QueryExtender controllo usa quindi la chiave in una Where clausola . In questo modo viene modificata la query per l'origine dati, che restituisce quindi righe di tabella filtrate in base alla chiave.
È anche possibile filtrare i dati usando una chiave esterna specificata tramite la ColumnName proprietà .
Sintassi dichiarativa
<asp:DynamicRouteExpression
ColumnName="Name of the foreign key column"/>
Costruttori
| Nome | Descrizione |
|---|---|
| DynamicRouteExpression() |
Inizializza una nuova istanza della classe DynamicRouteExpression. |
Proprietà
| Nome | Descrizione |
|---|---|
| ColumnName |
Ottiene o imposta il nome di una colonna contenente una chiave esterna utilizzata per eseguire query sull'origine dati. |
| Context |
Ottiene l'istanza HttpContext del controllo proprietario. (Ereditato da DataSourceExpression) |
| DataSource |
Ottiene l'oggetto origine dati associato al controllo proprietario. (Ereditato da DataSourceExpression) |
| IsTrackingViewState |
Ottiene un valore che indica se un oggetto espressione origine dati sta monitorando le modifiche apportate allo stato di visualizzazione. (Ereditato da DataSourceExpression) |
| Owner |
Ottiene il controllo proprietario. (Ereditato da DataSourceExpression) |
| ViewState |
Ottiene un'istanza della StateBag classe che contiene le informazioni sullo stato di visualizzazione corrente. (Ereditato da DataSourceExpression) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetQueryable(IQueryable) |
Ottiene la query dall'origine dati. |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| LoadViewState(Object) |
Carica lo stato dei valori nell'oggetto DataSourceExpression che deve essere salvato in modo permanente. (Ereditato da DataSourceExpression) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| SaveViewState() |
Salva lo stato di visualizzazione corrente dell'oggetto DataSourceExpression . (Ereditato da DataSourceExpression) |
| SetContext(Control, HttpContext, IQueryableDataSource) |
Imposta il contesto HTTP dell'oggetto DynamicRouteExpression . |
| SetDirty() |
Contrassegna l'oggetto DataSourceExpression in modo che il relativo stato venga salvato nello stato di visualizzazione. (Ereditato da DataSourceExpression) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
| TrackViewState() |
Tiene traccia delle modifiche dello stato di visualizzazione dell'oggetto DataSourceExpression in modo che le modifiche possano essere archiviate nell'oggetto per l'oggetto StateBag espressione origine dati. (Ereditato da DataSourceExpression) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| IStateManager.IsTrackingViewState |
Se implementato da una classe, ottiene un valore che indica se un oggetto espressione origine dati sta monitorando le modifiche dello stato di visualizzazione. (Ereditato da DataSourceExpression) |
| IStateManager.LoadViewState(Object) |
Se implementato da una classe, carica lo stato di visualizzazione salvato in precedenza dell'oggetto espressione origine dati. (Ereditato da DataSourceExpression) |
| IStateManager.SaveViewState() |
Se implementato da una classe, salva lo stato di visualizzazione corrente dell'oggetto DataSourceExpression . (Ereditato da DataSourceExpression) |
| IStateManager.TrackViewState() |
Se implementato da una classe, tiene traccia delle modifiche dello stato di visualizzazione dell'oggetto DataSourceExpression in modo che le modifiche possano essere archiviate nell'oggetto per l'oggetto StateBag espressione origine dati. (Ereditato da DataSourceExpression) |