IBindableTemplate 인터페이스

정의

DetailsViewFormView와 같은 데이터 바인딩된 ASP.NET 컨트롤이 템플릿 내용 섹션에서 ASP.NET 데이터 소스 컨트롤에 자동으로 바인딩할 수 있도록 합니다.

public interface class IBindableTemplate : System::Web::UI::ITemplate
public interface IBindableTemplate : System.Web.UI.ITemplate
type IBindableTemplate = interface
    interface ITemplate
Public Interface IBindableTemplate
Implements ITemplate
파생
구현

예제

다음 코드 예제에서는 어떻게를 FormView 제어 선언적으로 템플릿 내용 정의 제공한 데이터를 바인딩할를 SqlDataSource 컨트롤을 표시 하 고 기존 레코드를 편집 합니다. ASP.NET 파서 템플릿 콘텐츠를 구문 분석 하 고 만듭니다는 IBindableTemplate 의 값을 바인딩할 수 있는 런타임 시 개체는 SqlDataSource 모두 단방향 ASP.NET 데이터 바인딩 구문을 사용 하 여 템플릿에 정의 된 데이터 바인딩 영역 컨트롤 (<%# Eval("fieldname") %>) 및 양방향 데이터 바인딩을 구문 (<%# Bind("fieldname") %>).

중요

이 컨트롤은 잠재적 보안 위협에는 사용자 입력을 허용 하는 텍스트 상자를 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.


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

  void EmployeeFormView_ItemUpdating(Object sender, FormViewUpdateEventArgs e)
  {

    // Validate the field values entered by the user. This
    // example determines whether the user left any fields
    // empty. Use the NewValues property to access the new 
    // values entered by the user.
    ArrayList emptyFieldList = ValidateFields(e.NewValues);

    if (emptyFieldList.Count > 0)
    {

      // The user left some fields empty. Display an error message.
      
      // Use the Keys property to retrieve the key field value.
      String keyValue = e.Keys["EmployeeID"].ToString();

      MessageLabel.Text = "You must enter a value for each field of record " +
        keyValue + ".<br/>The following fields are missing:<br/><br/>";

      // Display the missing fields.
      foreach (String value in emptyFieldList)
      {
        // Use the OldValues property to access the original value
        // of a field.
        MessageLabel.Text += value + " - Original Value = " + 
          e.OldValues[value].ToString() + "<br />";
      }

      // Cancel the update operation.
      e.Cancel = true;

    }
    else
    {
      // The field values passed validation. Clear the
      // error message label.
      MessageLabel.Text = "";
    }

  }

  ArrayList ValidateFields(IOrderedDictionary list)
  {
    
    // Create an ArrayList object to store the
    // names of any empty fields.
    ArrayList emptyFieldList = new ArrayList();

    // Iterate though the field values entered by
    // the user and check for an empty field. Empty
    // fields contain a null value.
    foreach (DictionaryEntry entry in list)
    {
      if (entry.Value == String.Empty)
      {
        // Add the field name to the ArrayList object.
        emptyFieldList.Add(entry.Key.ToString());
      }
    }

    return emptyFieldList;
  }

  void EmployeeFormView_ModeChanging(Object sender, FormViewModeEventArgs e)
  {
    if (e.CancelingEdit)
    {
      // The user canceled the update operation.
      // Clear the error message label.
      MessageLabel.Text = "";
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        headertext="Employee Record"
        emptydatatext="No employees found."
        onitemupdating="EmployeeFormView_ItemUpdating"
        onmodechanging="EmployeeFormView_ModeChanging"  
        runat="server">
        
        <headerstyle backcolor="CornFlowerBlue"
          forecolor="White"
          font-size="14"
          horizontalalign="Center"  
          wrap="false"/>
        <rowstyle backcolor="LightBlue"
          wrap="false"/>
        <pagerstyle backcolor="CornFlowerBlue"/>

        <itemtemplate>
          <table>
            <tr>
              <td rowspan="6">
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td colspan="2">
                    
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <%# Eval("FirstName") %> <%# Eval("LastName") %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <%# Eval("Title") %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Hire Date:</b>                 
              </td>
              <td>
                <%# Eval("HireDate","{0:d}") %>
              </td>
            </tr>
            <tr style="height:150; vertical-align:top">
              <td>
                <b>Address:</b>
              </td>
              <td>
                <%# Eval("Address") %><br/>
                <%# Eval("City") %> <%# Eval("Region") %>
                <%# Eval("PostalCode") %><br/>
                <%# Eval("Country") %>   
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="Edit"
                  text="Edit"
                  commandname="Edit"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </itemtemplate>
        <edititemtemplate>
          <table>
            <tr>
              <td rowspan="6">
                <asp:image id="EmployeeEditImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td colspan="2">
                    
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <asp:textbox id="FirstNameUpdateTextBox"
                  text='<%# Bind("FirstName") %>'
                  runat="server"/>
                <asp:textbox id="LastNameUpdateTextBox"
                  text='<%# Bind("LastName") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <asp:textbox id="TitleUpdateTextBox"
                  text='<%# Bind("Title") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td>
                <b>Hire Date:</b>                 
              </td>
              <td>
                <asp:textbox id="HireDateUpdateTextBox"
                  text='<%# Bind("HireDate", "{0:d}") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr style="height:150; vertical-align:top">
              <td>
                <b>Address:</b>
              </td>
              <td>
                <asp:textbox id="AddressUpdateTextBox"
                  text='<%# Bind("Address") %>'
                  runat="server"/>
                <br/>
                <asp:textbox id="CityUpdateTextBox"
                  text='<%# Bind("City") %>'
                  runat="server"/> 
                <asp:textbox id="RegionUpdateTextBox"
                  text='<%# Bind("Region") %>'
                  width="40"
                  runat="server"/>
                <asp:textbox id="PostalCodeUpdateTextBox"
                  text='<%# Bind("PostalCode") %>'
                  width="60"
                  runat="server"/>
                <br/>
                <asp:textbox id="CountryUpdateTextBox"
                  text='<%# Bind("Country") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="UpdateButton"
                  text="Update"
                  commandname="Update"
                  runat="server"/>
                <asp:linkbutton id="CancelButton"
                  text="Cancel"
                  commandname="Cancel"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </edititemtemplate>
          
        <pagersettings position="Bottom"
          mode="Numeric"/> 
                  
      </asp:formview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country], [HireDate], [PhotoPath] From [Employees]"
        updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title, [Address]=@Address, [City]=@City, [Region]=@Region, [PostalCode]=@PostalCode, [Country]=@Country Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub EmployeeFormView_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs) Handles EmployeeFormView.ItemUpdating
  
    ' Validate the field values entered by the user. This
    ' example determines whether the user left any fields
    ' empty. Use the NewValues property to access the new 
    ' values entered by the user.
        Dim emptyFieldList As ArrayList = ValidateFields(e.NewValues)

    If emptyFieldList.Count > 0 Then

      ' The user left some fields empty. Display an error message.
      
      ' Use the Keys property to retrieve the key field value.
      Dim keyValue As String = e.Keys("EmployeeID").ToString()

      MessageLabel.Text = "You must enter a value for each field of record " & _
        keyValue & ".<br/>The following fields are missing:<br/><br/>"

      ' Display the missing fields.
      Dim value As String
      For Each value In emptyFieldList
      
        ' Use the OldValues property to access the original value
        ' of a field.
        MessageLabel.Text &= value & " - Original Value = " & _
          e.OldValues(value).ToString() & "<br />"
        
      Next

      ' Cancel the update operation.
      e.Cancel = True

    Else
    
      ' The field values passed validation. Clear the
      ' error message label.
      MessageLabel.Text = ""
      
    End If

  End Sub

  Function ValidateFields(ByVal list As IOrderedDictionary) As ArrayList
    
    ' Create an ArrayList object to store the
    ' names of any empty fields.
    Dim emptyFieldList As New ArrayList()

    ' Iterate though the field values entered by
    ' the user and check for an empty field. Empty
    ' fields contain a null value.
    Dim entry As DictionaryEntry
    
    For Each entry In list
    
      If entry.Value Is String.Empty Then
      
        ' Add the field name to the ArrayList object.
        emptyFieldList.Add(entry.Key.ToString())
        
      End If
      
    Next

    Return emptyFieldList
  
  End Function
  
  Sub EmployeeFormView_ModeChanging(ByVal sender As Object, ByVal e As FormViewModeEventArgs) Handles EmployeeFormView.ModeChanging
  
    If e.CancelingEdit Then
      
      ' The user canceled the update operation.
      ' Clear the error message label.
      MessageLabel.Text = ""
    
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormView Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        headertext="Employee Record"
        emptydatatext="No employees found."
        runat="server">
        
        <headerstyle backcolor="CornFlowerBlue"
          forecolor="White"
          font-size="14"
          horizontalalign="Center"  
          wrap="false"/>
        <rowstyle backcolor="LightBlue"
          wrap="false"/>
        <pagerstyle backcolor="CornFlowerBlue"/>

        <itemtemplate>
          <table>
            <tr>
              <td rowspan="6">
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td colspan="2">
                    
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <%# Eval("FirstName") %> <%# Eval("LastName") %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <%# Eval("Title") %>
              </td>
            </tr>
            <tr>
              <td>
                <b>Hire Date:</b>                 
              </td>
              <td>
                <%# Eval("HireDate","{0:d}") %>
              </td>
            </tr>
            <tr style="height:150; vertical-align:top">
              <td>
                <b>Address:</b>
              </td>
              <td>
                <%# Eval("Address") %><br/>
                <%# Eval("City") %> <%# Eval("Region") %>
                <%# Eval("PostalCode") %><br/>
                <%# Eval("Country") %>   
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="Edit"
                  text="Edit"
                  commandname="Edit"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </itemtemplate>
        <edititemtemplate>
          <table>
            <tr>
              <td rowspan="6">
                <asp:image id="EmployeeEditImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td colspan="2">
                    
              </td>
            </tr>
            <tr>
              <td>
                <b>Name:</b>
              </td>
              <td>
                <asp:textbox id="FirstNameUpdateTextBox"
                  text='<%# Bind("FirstName") %>'
                  runat="server"/>
                <asp:textbox id="LastNameUpdateTextBox"
                  text='<%# Bind("LastName") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr>
              <td>
                <b>Title:</b>
              </td>
              <td>
                <asp:textbox id="TitleUpdateTextBox"
                  text='<%# Bind("Title") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td>
                <b>Hire Date:</b>                 
              </td>
              <td>
                <asp:textbox id="HireDateUpdateTextBox"
                  text='<%# Bind("HireDate", "{0:d}") %>'
                  runat="server"/>
              </td>
            </tr>
            <tr style="height:150; vertical-align:top">
              <td>
                <b>Address:</b>
              </td>
              <td>
                <asp:textbox id="AddressUpdateTextBox"
                  text='<%# Bind("Address") %>'
                  runat="server"/>
                <br/>
                <asp:textbox id="CityUpdateTextBox"
                  text='<%# Bind("City") %>'
                  runat="server"/> 
                <asp:textbox id="RegionUpdateTextBox"
                  text='<%# Bind("Region") %>'
                  width="40"
                  runat="server"/>
                <asp:textbox id="PostalCodeUpdateTextBox"
                  text='<%# Bind("PostalCode") %>'
                  width="60"
                  runat="server"/>
                <br/>
                <asp:textbox id="CountryUpdateTextBox"
                  text='<%# Bind("Country") %>'
                  runat="server"/> 
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <asp:linkbutton id="UpdateButton"
                  text="Update"
                  commandname="Update"
                  runat="server"/>
                <asp:linkbutton id="CancelButton"
                  text="Cancel"
                  commandname="Cancel"
                  runat="server"/> 
              </td>
            </tr>
          </table>       
        </edititemtemplate>
          
        <pagersettings position="Bottom"
          mode="Numeric"/> 
                  
      </asp:formview>
      
      <br/><br/>
      
      <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
          
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [Address], [City], [Region], [PostalCode], [Country], [HireDate], [PhotoPath] From [Employees]"
        updatecommand="Update [Employees] Set [LastName]=@LastName, [FirstName]=@FirstName, [Title]=@Title, [Address]=@Address, [City]=@City, [Region]=@Region, [PostalCode]=@PostalCode, [Country]=@Country Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

설명

합니다 IBindableTemplate 인터페이스를 통해 ASP.NET 데이터 바인딩된 컨트롤에 대 한 같은 DetailsViewGridView, 및 FormView와 같은 ASP.NET 데이터 소스 컨트롤에서 제공 하는 데이터에 바인딩할 ObjectDataSource 또는 SqlDataSource경우는 데이터 바인딩된 컨트롤에는 템플릿 기반 콘텐츠가 포함 됩니다.

참고

페이지 개발자가 구현 하지 않습니다는 IBindableTemplate 인터페이스입니다. 사용자 지정 데이터 바인딩된 컨트롤을 만드는 개발자를 조작할 수 있습니다 IBindableTemplate 의 구현에서 개체를 PerformDataBinding 하 고 ExtractRowValues 메서드를 구현 하지는 않습니다 자신의 IBindableTemplate 개체.

와 같은 데이터 바인딩된 컨트롤 GridView 일반적으로 해당 자식 컨트롤 트리의 인식 수 있으므로 값을 바인딩하고에서 값을 추출 및 데이터 바인딩이 발생할 때마다 데이터 바인딩된 컨트롤과 데이터 소스 컨트롤 간의 이러한 값을 전달 . 그러나 페이지 개발자는 데이터 바인딩된 컨트롤에 대 한 템플릿 기반 콘텐츠를 정의 하는 경우 템플릿 내에서 자식 컨트롤에 표시 되지 않습니다 데이터 바인딩된 부모 컨트롤이: 부모는 자식 렌더링할 수 있습니다 (컨트롤 자체에 효과적으로 렌더링) 때문에 콘텐츠를 하지만 연결 된 데이터 소스 컨트롤의 업데이트, 삽입 또는 삭제 작업에 전달할 이러한 자식 컨트롤의 값을 추출할 수 없습니다. 데이터 바인딩 시나리오에서 템플릿 기반 콘텐츠는 부모 데이터 바인딩된 컨트롤에 불투명 합니다. 합니다 Bind 구문을 사용 하면 데이터 바인딩된 컨트롤 내에서 데이터 바인딩된 컨트롤에서 값을 추출 하는 IBindableTemplate 인스턴스.

단방향 또는 양방향 데이터 바인딩을 수 있습니다. (이러한 바인딩 방향은 정의한는 BindingDirection 열거형입니다.) 단방향 데이터 바인딩을 데이터 바인딩된 컨트롤을 데이터 소스 컨트롤에서 아웃 바운드 방향, 수행 된 모든 데이터 바인딩 예를 들어, 모든 데이터 읽기 시나리오에는 단방향 데이터 바인딩을 포함합니다. 단방향 데이터 바인딩에 대 한 단방향 데이터 바인딩 구문을 사용할 수 있습니다 (<%# Eval("fieldname") %>) 내 템플릿 내용에서 양방향 ASP.NET 데이터 바인딩 구문을 사용 하 여 필요 하지 않습니다. 양방향 데이터 바인딩을 데이터 바인딩된 데이터 소스 컨트롤에 데이터 바인딩된 컨트롤에서 인바운드 방향의 설명합니다. 자동 편집, 삽입 및 삭제 시나리오 ASP.NET을 사용 하 여 데이터 바인딩 및 데이터 소스 컨트롤은 양방향 데이터 바인딩 시나리오입니다. 이러한 시나리오에서는 양방향 데이터 바인딩 식 (<%# Bind("fieldname") %>). IBindableTemplate 인터페이스와 ASP.NET 인프라 ASP.NET 데이터 소스 컨트롤에서 템플릿 내용 사이의 자동 높고 선언적 이며 양방향 데이터 바인딩을 지원 합니다. ASP.NET 데이터 바인딩 식 및 구문에 대 한 자세한 내용은 참조 하세요. 데이터베이스를 바인딩할 하 고 데이터 바인딩 식을 개요합니다.

데이터 바인딩된 컨트롤에 대 한 템플릿 내용 대부분 선언적으로 정의 됩니다. 다음 표에서 가장 일반적으로 템플릿 데이터를 데이터 바인딩된 컨트롤에 바인딩하는 데 사용 하는 프로세스를 설명 합니다.

데이터 바인딩된 컨트롤 프로세스
DetailsView 데이터 바인딩된 컨트롤을 사용 하 여 데이터에 바인딩된 합니다 DataSourceID 템플릿 내용 및 데이터 소스 컨트롤의 속성에 정의 된를 ItemTemplateEditItemTemplate 또는 InsertItemTemplate 속성입니다.
GridView 데이터 바인딩된 컨트롤을 사용 하 여 데이터에 바인딩된 합니다 DataSourceID 템플릿 내용 및 데이터 소스 컨트롤의 속성에 정의 된를 ItemTemplate 또는 EditItemTemplate 속성입니다. GridView 컨트롤 삽입 작업을 지원 하지 않습니다.
FormView 데이터 바인딩된 컨트롤을 사용 하 여 데이터에 바인딩되어를 DataSourceID 속성 및 템플릿 내용에 정의 된는 ItemTemplate, InsertItemTemplate, 또는 EditItemTemplate 속성 또는 TemplateField 개체입니다.

합니다 DataListRepeater 컨트롤 자동 양방향 데이터 바인딩 시나리오를 지원 하지 않습니다.

ASP.NET이 암시적으로 생성 하는 IBindableTemplate 템플릿 내에서 ASP.NET 데이터 소스 컨트롤에 바인딩되는 템플릿 기반 콘텐츠 구문 분석 하는 개체입니다. ASP.NET 파서의 인스턴스를 만들고 특히는 CompiledBindableTemplateBuilder ASP.NET 데이터 바인딩 구문을 사용 하 고 데이터 바인딩을 지 원하는 ASP.NET 웹 서버 컨트롤을 포함 하는 템플릿 콘텐츠를 구문 분석할 때 클래스입니다. 이러한 ASP.NET 서버 컨트롤에서 표시 되는 BindableAttribute 특성입니다.

합니다 IBindableTemplate 인터페이스 메서드를 정의 ExtractValues합니다. 이 메서드는 자동으로 템플릿 내용에서 이름/값 쌍을 추출 하 고 런타임에 데이터 소스 컨트롤 쌍을 전달할 수 데이터 바인딩된 컨트롤을 양방향 데이터 바인딩을 위한 정의 됩니다. 자동 데이터 바인딩에 성공 하려면에 대 한 필드 이름은 템플릿 내용에서 추출 된 ExtractValues 메서드는 연결 된 데이터 소스 컨트롤의 매개 변수 이름은 일치 해야 합니다. 개발자 호출을 제어 합니다 ExtractValues 메서드 명시적으로의 구현이 ExtractRowValues 또는 사용자 지정 데이터 바인딩된 컨트롤의 다른 유사 메서드.

메서드

ExtractValues(Control)

클래스에 의해 구현될 때 템플릿 내용에서 양방향 ASP.NET 데이터 바인딩 구문을 사용하여 바인딩된 값의 이름/값 쌍 집합을 검색합니다.

InstantiateIn(Control)

클래스에서 구현될 때, 자식 컨트롤 및 템플릿이 속해 있는 Control 개체를 정의합니다. 그러면 이 자식 컨트롤이 인라인 템플릿에 정의됩니다.

(다음에서 상속됨 ITemplate)

적용 대상

추가 정보