DynamicDataExtensions.FindDataSourceControl(Control) 메서드

정의

지정된 컨트롤에 대한 데이터 컨트롤에 연결된 데이터 소스를 반환합니다.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Web::DynamicData::IDynamicDataSource ^ FindDataSourceControl(System::Web::UI::Control ^ current);
public static System.Web.DynamicData.IDynamicDataSource FindDataSourceControl (this System.Web.UI.Control current);
static member FindDataSourceControl : System.Web.UI.Control -> System.Web.DynamicData.IDynamicDataSource
<Extension()>
Public Function FindDataSourceControl (current As Control) As IDynamicDataSource

매개 변수

current
Control

찾으려는 상위 컨트롤에 포함된 데이터 바인딩된 컨트롤의 계층 구조 내에 있는 컨트롤입니다.

반환

IDynamicDataSource

지정된 컨트롤에 대한 데이터 컨트롤에 연결된 데이터 소스입니다.

예제

다음 예제에서는 포함 된 데이터 소스 제어를 찾는 방법을 보여 있습니다. 이 예제에서 Dynamic Data 페이지 템플릿은 AdventureWorksLT 데이터베이스의 ProductDescription 테이블에 대한 사용자 지정 표시를 제공하기 위해 \DynamicData\CustomPages\ProductDescriptions 폴더에 복사됩니다. Insert.aspx 파일 태그는 데이터 소스 컨트롤을 OnDataBound 찾기 위해 메서드가 호출되는 FindDataSourceControl 이벤트 DetailsView1_DataBound처리기를 추가하도록 변경됩니다.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
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;
using System.Xml.Linq;
using System.Web.DynamicData;

public partial class Insert : System.Web.UI.Page {
    protected MetaTable table;

    protected void Page_Init(object sender, EventArgs e) {
        DynamicDataManager1.RegisterControl(DetailsView1);
    }

    protected void Page_Load(object sender, EventArgs e) {
        table = DetailsDataSource.GetTable();
        Title = table.DisplayName;
    }

    protected void DetailsView1_DataBound(object sender, EventArgs e) {

        var dsc = DetailsView1.FindDataSourceControl() as LinqDataSource;
        if (dsc == null || dsc.EnableInsert != true)
            return;

        var mTbl = DetailsView1.FindMetaTable() as MetaTable;
        if (mTbl != null)
            LblMetaTbl.Text = "Column count = " + mTbl.Columns.Count.ToString();

        var fldTmpUsrCtl = DetailsView1.FindFieldTemplate("Description") as FieldTemplateUserControl;
        if (fldTmpUsrCtl != null) {
            var entryFldDescript = fldTmpUsrCtl.DataControl as TextBox;
            entryFldDescript.Text = "(Enter short Description here.)";
        }

        var fldTmpUsrCtl2 = DetailsView1.FindFieldTemplate("ModifiedDate") as FieldTemplateUserControl;
        if (fldTmpUsrCtl2 != null) {
            var entryFldModDate = fldTmpUsrCtl2.DataControl as TextBox;
            entryFldModDate.Text = System.DateTime.Now.Date.ToShortDateString();
        }
    }

    protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e) {
        if (e.CommandName == DataControlCommands.CancelCommandName) {
            Response.Redirect(table.ListActionPath);
        }
    }

    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) {
        if (e.Exception == null) {
            Response.Redirect(table.ListActionPath);
        }
    }
}
<%@ Page Language="C#" MasterPageFile="~/Site.master" CodeFile="Insert.aspx.cs" Inherits="Insert" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

    <h2> DynamicData\CustomPages\ProductDescriptions\Insert.aspx <%= table.DisplayName %></h2>
    <p>   <asp:Label ID="LblMetaTbl" runat="server" Text="Label"></asp:Label>   </p>

    <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
        HeaderText="List of validation errors" />
    <asp:DynamicValidator runat="server" ID="DetailsViewValidator" ControlToValidate="DetailsView1" Display="None" />

    <asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="DetailsDataSource" DefaultMode="Insert"
        AutoGenerateInsertButton="True" OnItemCommand="DetailsView1_ItemCommand" OnItemInserted="DetailsView1_ItemInserted"
        CssClass="detailstable" FieldHeaderStyle-CssClass="bold"
        OnDataBound="DetailsView1_DataBound">
    </asp:DetailsView>

    <asp:LinqDataSource ID="DetailsDataSource" runat="server" EnableInsert="true">
    </asp:LinqDataSource>
</asp:Content>

적용 대상