Share via


DynamicRouteExpression クラス

定義

データのフィルター処理を実行するために、ルーティング情報から主キーを取得します。

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
継承
DynamicRouteExpression

ソース コードを含むVisual Studio プロジェクトを使用して、動的データのスキャフォールディングに関するトピックを参照してください。

次の例は、Products テーブルのカスタム List.aspx ページ テンプレートを示しています。 このプロパティを ColumnName 使用して、Products 行をフィルター処理するための ProductCategory 外部キーを指定します。

カスタム List.aspx ページには、ProductCategory 外部キー列に含まれるカテゴリのリンクを含む列が表示されます。 ユーザーがこれらのリンクのいずれかをクリックすると、List.aspx ページには、選択したカテゴリを含む行のみが表示されます。

この例では、次のものが必要です。

<%@ 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

注釈

この DynamicRouteExpression クラスは、ページ マークアップ内の QueryExtender コントロールと共に使用されます。 このクラスは DynamicRouteExpression 、Web 要求に含まれるルーティング情報から主キーを取得します。 次に、コントロールは QueryExtender 句でキーを Where 使用します。 これにより、データ ソースのクエリが変更され、キーによってフィルター処理されたテーブル行が返されます。

プロパティを使用して指定した外部キーを使用してデータを ColumnName フィルター処理することもできます。

宣言型の構文

<asp:DynamicRouteExpression  
  ColumnName="Name of the foreign key column"/>  

コンストラクター

DynamicRouteExpression()

DynamicRouteExpression クラスの新しいインスタンスを初期化します。

プロパティ

ColumnName

データ ソースのクエリに使用される外部キーを含む列の名前を取得または設定します。

Context

所有者コントロールの HttpContext インスタンスを取得します。

(継承元 DataSourceExpression)
DataSource

所有者コントロールに関連付けられているデータ ソース オブジェクトを取得します。

(継承元 DataSourceExpression)
IsTrackingViewState

データ ソース式オブジェクトがビューステートの変更を追跡しているかどうかを示す値を取得します。

(継承元 DataSourceExpression)
Owner

所有者コントロールを取得します。

(継承元 DataSourceExpression)
ViewState

現在のビューステートの情報を格納している StateBag クラスのインスタンスを取得します。

(継承元 DataSourceExpression)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetQueryable(IQueryable)

データ ソースからクエリを取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
LoadViewState(Object)

永続化する必要がある DataSourceExpression オブジェクト内の値の状態を読み込みます。

(継承元 DataSourceExpression)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
SaveViewState()

DataSourceExpression オブジェクトの現在のビューステートを保存します。

(継承元 DataSourceExpression)
SetContext(Control, HttpContext, IQueryableDataSource)

DynamicRouteExpression オブジェクトの HTTP コンテキストを設定します。

SetDirty()

DataSourceExpression オブジェクトの状態がビューステートで保存されるように、このオブジェクトをマークします。

(継承元 DataSourceExpression)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
TrackViewState()

DataSourceExpression オブジェクトのビューステートの変更を追跡し、その変更をデータ ソース式オブジェクトに対応する StateBag オブジェクトに格納できるようにします。

(継承元 DataSourceExpression)

明示的なインターフェイスの実装

IStateManager.IsTrackingViewState

クラスによって実装されると、データ ソース式オブジェクトがビューステートの変更を追跡しているかどうかを示す値を取得します。

(継承元 DataSourceExpression)
IStateManager.LoadViewState(Object)

クラスによって実装されると、データ ソース式オブジェクトの前回保存されたビューステートを読み込みます。

(継承元 DataSourceExpression)
IStateManager.SaveViewState()

クラスによって実装されると、DataSourceExpression オブジェクトの現在のビューステートを保存します。

(継承元 DataSourceExpression)
IStateManager.TrackViewState()

クラスによって実装されると、DataSourceExpression オブジェクトのビューステートの変更を追跡し、データ ソース式オブジェクトに対応する StateBag オブジェクトに、その変更を保存できるようにします。

(継承元 DataSourceExpression)

適用対象