IBindableTemplateとは? わかりやすく解説

IBindableTemplate インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

DetailsView や FormView などの ASP.NET データ バインド コントロールが、テンプレート コンテンツ セクション内の ASP.NET データ ソース コントロール自動的にバインドできるようにします。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Interface IBindableTemplate
    Inherits ITemplate
Dim instance As IBindableTemplate
public interface IBindableTemplate : ITemplate
public interface class IBindableTemplate :
 ITemplate
public interface IBindableTemplate extends ITemplate
public interface IBindableTemplate extends
 ITemplate
解説解説

IBindableTemplate インターフェイス使用すると、データ バインド コントロールテンプレート コンテンツ含まれている場合に、DetailsView、GridView、FormView などの ASP.NET データ バインド コントロールを ObjectDataSource または SqlDataSource などの ASP.NET データ ソース コントロール指定されデータバインドできます

メモメモ

ページ開発者IBindableTemplate インターフェイス実装しません。カスタムデータ バインド コントロール作成している開発者IBindableTemplate オブジェクトを PerformDataBinding メソッドおよび ExtractRowValues メソッド実装操作する場合ありますが、独自の IBindableTemplate オブジェクト実装しません。

GridView などのデータ バインド コントロールでは、通常、子コントロールツリー認識されます。そのため、データ バインディングが行われるたびに、データ バインド コントロールに値をバインドしたり、データ バインド コントロールから値を抽出したできますまた、データ バインド コントロールデータ ソース コントロール間で値をやりとりできます。ただし、ページ開発者データ バインド コントロールテンプレート コンテンツ定義すると、親データ バインド コントロールからはそのテンプレート内のコントロール認識されません。(コントロールコントロール自体効果的に描画するので) 親コントロールその子コントロールコンテンツ描画できますが、これらの子コントロールの値を抽出し関連付けられているデータ ソース コントロール更新挿入、または削除操作に渡すことはできません。データ バインディングでは、テンプレート コンテンツは親のデータ バインド コントロールには不透明です。Bind 構文使用すると、データ バインド コントロール使用してIBindableTemplate インスタンス内でデータバインドされているコントロールから値を抽出できます

データ バインディング一方向または双方向実行できます (これらのバインディング方向は、BindingDirection 列挙体によって定義されます)。一方向データ バインディングは、データ ソース コントロールからデータ バインド コントロールへの送信方向実行されるデータ バインディングです。たとえば、データ読み取りでは一方向データ バインディングが行われます一方向データ バインディングでは、テンプレート コンテンツ内で一方向データ バインディング構文 (<%# Eval("fieldname") %>) を使用できるので、双方向ASP.NET データ バインディング構文使用する要はありません。双方向データ バインディングは、データ バインド コントロールかデータ ソース コントロールへの着信方向データ バインディング表しますASP.NETデータ バインド コントロールおよびデータ ソース コントロール使用した自動的な編集挿入、および削除双方向データ バインディングです。このような場合は、双方向データ バインディング式 (<%# Bind("fieldname") %>) を使用しますIBindableTemplate インターフェイスおよび ASP.NET インフラストラクチャでは、ASP.NET データ ソース コントロールテンプレート コンテンツの間で、自動的な宣言による双方向データ バインディングサポートしてます。ASP.NETデータ バインディング式およびデータ バインディング構文詳細については、「データベースへのバインド」および「データ バインディング式の構文」を参照してください

データ バインド コントロールテンプレート コンテンツは、ほとんどの場合宣言使用して定義されます。次の表に、テンプレート データデータ バインド コントロールバインドするために使用する最も一般的なプロセス示します

DataList コントロールおよび Repeater コントロールでは、自動的な双方向データ バインディングサポートされません。

テンプレート内の ASP.NET データ ソース コントロールバインドされるテンプレート コンテンツ解析時にASP.NET によって暗黙的に IBindableTemplate オブジェクト作成されます。具体的には、ASP.NET データ バインディング構文使用しデータ バインディングサポートする ASP.NET Web サーバー コントロールを含むテンプレート コンテンツASP.NET パーサーにより解析されるときに、ASP.NET パーサーによって CompiledBindableTemplateBuilder クラスインスタンス作成されます。これらの ASP.NET サーバー コントロールは、BindableAttribute 属性マークされます。

IBindableTemplate インターフェイスでは、1 つメソッド ExtractValues が定義されます。このメソッドは、双方向データ バインディングに対して定義されるので、データ バインド コントロールにより自動的に名前と値のペアがテンプレート コンテンツから抽出されて、そのペアがデータ ソース コントロール実行時渡されます。自動的なデータ バインディング成功するには、ExtractValues メソッドによって抽出されテンプレート コンテンツフィールド名が、関連付けられているデータ ソース コントロールパラメータ名と一致する必要がありますコントロール開発者は、ExtractValues メソッドを、ExtractRowValues メソッド、または他のカスタムデータ バインド コントロール類似メソッド実装する場合限り明示的に呼び出します。

使用例使用例

FormView コントロール使用してテンプレート コンテンツ宣言によって定義しSqlDataSource コントロール指定したデータバインドし、既存レコード表示および編集する方法次のコード例示しますASP.NET パーサーは、実行時テンプレート コンテンツ解析しIBindableTemplate オブジェクト作成します。このオブジェクトは、一方向ASP.NET データ バインディング構文 (<%# Eval("fieldname") %>) と双方向ASP.NET データ バインディング構文 (<%# Bind("fieldname") %>) の両方によってテンプレート定義されているデータ バインド領域に、SqlDataSource コントロールの値をバインドできます

<%@ Page language="VB" %>

<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>
  <body>
    <form 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">
                  &nbsp; 
              </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 height="150" valign="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">
                  &nbsp; 
              </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 height="150" valign="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="C#" %>

<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>
  <body>
    <form 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">
                  &nbsp; 
              </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 height="150" valign="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">
                  &nbsp; 
              </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 height="150" valign="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 メンバ
System.Web.UI 名前空間
ITemplate
CompiledBindableTemplateBuilder クラス
ExtractTemplateValuesMethod デリゲート
BindableAttribute
BindingDirection

IBindableTemplate メソッド


パブリック メソッドパブリック メソッド

参照参照

関連項目

IBindableTemplate インターフェイス
System.Web.UI 名前空間
ITemplate
CompiledBindableTemplateBuilder クラス
ExtractTemplateValuesMethod デリゲート
BindableAttribute
BindingDirection

IBindableTemplate メンバ

DetailsView や FormView などの ASP.NET データ バインド コントロールが、テンプレート コンテンツ セクション内の ASP.NET データ ソース コントロール自動的にバインドできるようにします。

IBindableTemplate データ型公開されるメンバを以下の表に示します


パブリック メソッドパブリック メソッド
参照参照

関連項目

IBindableTemplate インターフェイス
System.Web.UI 名前空間
ITemplate
CompiledBindableTemplateBuilder クラス
ExtractTemplateValuesMethod デリゲート
BindableAttribute
BindingDirection



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「IBindableTemplate」の関連用語

IBindableTemplateのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



IBindableTemplateのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS