TemplateField.EditItemTemplate 속성

정의

TemplateField 개체에서 편집 모드의 항목을 표시하기 위한 템플릿을 가져오거나 설정합니다.

public:
 virtual property System::Web::UI::ITemplate ^ EditItemTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.IDataItemContainer), System.ComponentModel.BindingDirection.TwoWay)]
public virtual System.Web.UI.ITemplate EditItemTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.IDataItemContainer), System.ComponentModel.BindingDirection.TwoWay)>]
member this.EditItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EditItemTemplate As ITemplate

속성 값

ITemplate

ITemplate에서 편집 모드의 항목을 표시하기 위한 템플릿이 들어 있는 TemplateField 구현 개체입니다. 기본값은 null로, 이 속성이 설정되어 있지 않음을 나타냅니다.

특성

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 EditItemTemplate 속성에서 편집 모드의 항목에 대 한 사용자 지정 템플릿을 만들려면를 TemplateField 필드 열의 GridView 컨트롤. 템플릿에 사용자가 값 필드를 비워 두면 하지 못하게 하려면 유효성 검사 서버 컨트롤을 포함 합니다.

<%@ 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 AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs e)
  {
    
    // The GridView control does not automatically extract updated values 
    // from TemplateField column fields. These values must be added manually 
    // to the NewValues dictionary.
    
    // Get the GridViewRow object that represents the row being edited
    // from the Rows collection of the GridView control.
    int index = AuthorsGridView.EditIndex;
    GridViewRow row = AuthorsGridView.Rows[index];
    
    // Get the controls that contain the updated values. In this
    // example, the updated values are contained in the TextBox 
    // controls declared in the edit item templates of each TemplateField 
    // column fields in the GridView control.
    TextBox lastName = (TextBox)row.FindControl("LastNameTextBox");
    TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox");
    
    // Add the updated values to the NewValues dictionary. Use the
    // parameter names declared in the parameterized update query 
    // string for the key names.
    e.NewValues["au_lname"] = lastName.Text;
    e.NewValues["au_fname"] = firstName.Text;    
          
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TemplateField EditItemTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>TemplateField EditItemTemplate Example</h3>

      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames attribute as read-only.   -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        autogenerateeditbutton="true"
        datakeynames="au_id"
        cellpadding="10"
        onrowupdating="AuthorsGridView_RowUpdating"      
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="au_id"
            headertext="Author ID"
            readonly="true"/>
            
          <asp:templatefield headertext="Last Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_lname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                display="Dynamic"
                text="Please enter a last name." 
                runat="server" />                                      
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_fname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                display="Dynamic"
                text="Please enter a first name."
                runat="server" />                      
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:checkboxfield datafield="contract" 
            headertext="Contract"
            readonly="true"/>
            
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                         -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"             
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)" 
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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 AuthorsGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    
    ' The GridView control does not automatically extract updated values 
    ' from TemplateField column fields. These values must be added manually 
    ' to the NewValues dictionary.
    
    ' Get the GridViewRow object that represents the row being edited
    ' from the Rows collection of the GridView control.
    Dim index As Integer = AuthorsGridView.EditIndex
    Dim row As GridViewRow = AuthorsGridView.Rows(index)
    
    ' Get the controls that contain the updated values. In this
    ' example, the updated values are contained in the TextBox 
    ' controls declared in the edit item templates of each TemplateField 
    ' column fields in the GridView control.
    Dim lastName As TextBox = CType(row.FindControl("LastNameTextBox"), TextBox)
    Dim firstName As TextBox = CType(row.FindControl("FirstNameTextBox"), TextBox)
    
    ' Add the updated values to the NewValues dictionary. Use the
    ' parameter names declared in the parameterized update query 
    ' string for the key names.
    e.NewValues("au_lname") = lastName.Text
    e.NewValues("au_fname") = firstName.Text
          
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TemplateField EditItemTemplate Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>TemplateField EditItemTemplate Example</h3>

      <!-- The GridView control automatically sets the columns     -->
      <!-- specified in the datakeynames attribute as read-only.   -->
      <!-- No input controls are rendered for these columns in     -->
      <!-- edit mode.                                              -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        autogenerateeditbutton="true"
        datakeynames="au_id"
        cellpadding="10"
        onrowupdating="AuthorsGridView_RowUpdating"      
        runat="server">
                
        <columns>
        
          <asp:boundfield datafield="au_id"
            headertext="Author ID"
            readonly="true"/>
            
          <asp:templatefield headertext="Last Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_lname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="LastNameTextBox"
                text='<%#Eval("au_lname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="LastNameRequiredValidator"
                controltovalidate="LastNameTextBox"
                display="Dynamic"
                text="Please enter a last name." 
                runat="server" />                                      
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:templatefield headertext="First Name"
            itemstyle-verticalalign="Top">
            
            <itemtemplate>
              <%#Eval("au_fname")%>
            </itemtemplate>
            
            <edititemtemplate>
              <asp:textbox id="FirstNameTextBox"
                text='<%#Eval("au_fname")%>'
                width="90"
                runat="server"/>
              <br/>
              <asp:requiredfieldvalidator id="FirstNameRequiredValidator"
                controltovalidate="FirstNameTextBox"
                display="Dynamic"
                text="Please enter a first name."
                runat="server" />                      
            </edititemtemplate>
            
          </asp:templatefield>
          
          <asp:checkboxfield datafield="contract" 
            headertext="Contract"
            readonly="true"/>
            
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                         -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [contract] FROM [authors]"             
        updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname WHERE (authors.au_id = @au_id)" 
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

설명

사용 된 EditItemTemplate 속성에서 편집 모드에 있는 항목에 대해 표시 되는 사용자 지정 내용을 지정 하는 TemplateField 개체. 편집 모드의 항목은 렌더링 하는 방법을 지정 하는 템플릿을 만들어 콘텐츠를 정의 합니다. EditItemTemplate 속성은 일반적으로 데이터 원본에서 값을 수정 하려면 사용자에 대 한 입력된 컨트롤을 포함 합니다.

서식 파일을 지정 하려면 먼저 배치 열고 닫는 <EditItemTemplate> 을 열고 닫는 태그 사이 <TemplateField> 요소입니다. 다음으로 열기 및 닫기 사이 있는 사용자 지정 내용을 추가 <EditItemTemplate> 태그입니다. 콘텐츠는 일반 텍스트 만큼 간단 하거나 복잡 (다른 컨트롤 템플릿에 포함, 예를 들어) 수 있습니다.

템플릿에 정의 된 컨트롤에 프로그래밍 방식으로 액세스 하려면 먼저 결정 TableCell 개체 데이터 바인딩된 컨트롤에서 컨트롤을 포함 합니다. 다음을 사용 하 여는 Controls 의 컬렉션을 TableCell 컨트롤에 액세스 하는 개체입니다. 사용할 수도 있습니다는 FindControl 메서드를 TableCell 개체를 컨트롤에 컨트롤을 찾을 ID 지정 된 속성입니다.

적용 대상

추가 정보