TemplateField.InsertItemTemplate 속성

정의

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

public:
 virtual property System::Web::UI::ITemplate ^ InsertItemTemplate { 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 InsertItemTemplate { 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.InsertItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property InsertItemTemplate As ITemplate

속성 값

ITemplate

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

특성

예제

다음 코드 예제에 사용 하는 방법을 보여 줍니다.는 InsertItemTemplate 에서 삽입 모드의 항목에 대 한 사용자 지정 템플릿을 만들려면 속성을 TemplateField 필드 행에는 DetailsView 컨트롤입니다. 템플릿 표시를 DropDownList 컨트롤을 미리 정의 된 목록에서 값을 선택할 수 있도록 합니다.


<%@ 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 StoresGridView_SelectedIndexChanged(Object sender, EventArgs e)
  {
    // Set the DataItemIndex property of the DetailsView control to display
    // the record selected from the GridView control.
   // StoresDetailView.DataItemIndex = StoresGridView.SelectedIndex;
  }
  
  void StoresDetailView_ItemInserting(Object sender, DetailsViewInsertEventArgs e)
  {
    // Get the state value from the DropDownList control in the 
    // DetailsView control.
    String state = GetState(); 
    
    // Add the state to the dictionary of values to 
    // insert into the database.
    e.Values["state"] = state;
  }
  
  void StoresDetailView_ItemInserted (Object sender, DetailsViewInsertedEventArgs e)
  {
    // Refresh the GridView control after a new record is inserted.
    StoresGridView.DataBind ();
  }
  
  String GetState()
  {
    String state;
    
    // Get the DropDownList control that contains the state value
    // in the DetailsView control.
    DropDownList list = (DropDownList)StoresDetailView.Rows[4].FindControl("StateList");
    
    if (list != null)
    {
      // Get the selected value of the DropDownList control.
      state = list.SelectedItem.Text;
    }
    else
    {
      // Set the state to an empty string ("").
      state = "";
    }
    
    return state;
  }

</script>

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

        <table cellspacing="10">
            
          <tr>
              
            <td>
                
              <asp:gridview id="StoresGridView" 
                datasourceid="StoresSqlDataSource" 
                autogeneratecolumns="false"
                autogenerateselectbutton="true"
                datakeynames="stor_id"
                onselectedindexchanged="StoresGridView_SelectedIndexChanged"   
                runat="server">
                
                <headerstyle backcolor="Blue"
                  forecolor="White"/>
                
                <columns>
                
                  <asp:boundfield datafield="stor_name"
                    headertext="Store Name"/>
                    
                  <asp:boundfield datafield="stor_address"
                    headertext="Address"/>
                    
                  <asp:boundfield datafield="city"
                    headertext="City"/>
                        
                  <asp:boundfield datafield="state"
                    headertext="State"/>
                    
                  <asp:boundfield datafield="zip"
                    headertext="ZIP Code"/>
                    
                </columns>
                
              </asp:gridview>
            
            </td>
                
            <td valign="top">
                
              <asp:detailsview id="StoresDetailView"
                datasourceid="StoresDetailsSqlDataSource"
                autogenerateinsertbutton="true"
                autogeneraterows="false" 
                datakeynames="stor_id"        
                gridlines="Both"
                oniteminserting="StoresDetailView_ItemInserting"
                oniteminserted="StoresDetailView_ItemInserted"    
                runat="server">
                
                <headerStyle backcolor="Navy"
                  forecolor="White"/>
                  <Fields>               
                  
                  <asp:boundfield datafield="stor_id"
                    headertext="Store ID"/>
                    
                  <asp:boundfield datafield="stor_name"
                    headertext="Store Name"/>
                    
                  <asp:boundfield datafield="stor_address"
                    headertext="Address"/>
                    
                  <asp:boundfield datafield="city"
                    headertext="City"/>
                        
                  <asp:templatefield headertext="State">
                    <itemtemplate>
                      <%#Eval("state")%>
                    </itemtemplate>
                    <insertitemtemplate>
                      <asp:dropdownlist id="StateList"
                        datasourceid="StateSqlDataSource"
                        datatextfield="state" 
                        runat="server"/>
                    </insertitemtemplate>
                  </asp:templatefield>
                    
                  <asp:boundfield datafield="zip"
                    headertext="ZIP Code"/>
                    
                </Fields>                    
              </asp:detailsview>
            
            </td>
                
          </tr>
            
        </table>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        <asp:sqldatasource id="StoresSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" 
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
            
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]"
          insertcommand="INSERT INTO stores([stor_id], [stor_name], [stor_address], [city], [state], [zip]) VALUES (@stor_id, @stor_name, @stor_address, @city, @state, @zip)" 
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
        
        <!-- For this example, the states are retrieved from the  -->
        <!-- state field. For your application, you should use a  -->
        <!-- more complete source for the state values.           -->
        <asp:sqldatasource id="StateSqlDataSource"  
          selectcommand="SELECT Distinct [state] FROM [stores]"
          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 StoresGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    ' Set the DataItemIndex property of the DetailsView control to display
    ' the record selected from the GridView control.
        '  StoresDetailView.DataItem = StoresGridView.SelectedIndex
  
  End Sub
  
  Sub StoresDetailView_ItemInserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs)

    ' Get the state value from the DropDownList control in the 
    ' DetailsView control.
    Dim state As String = GetState()
    
    ' Add the state to the dictionary of values to 
    ' insert into the database.
    e.Values("state") = state
  
  End Sub
  
    Sub StoresDetailView_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs)

        ' Refresh the GridView control after a new record is inserted.
        StoresGridView.DataBind()
   
    End Sub
  
  Function GetState() As String

    Dim state As String
        
    ' Get the DropDownList control that contains the state value
    ' in the DetailsView control.
    Dim list As DropDownList = CType(StoresDetailView.Rows(4).FindControl("StateList"), DropDownList)
    
    If Not list Is Nothing Then

      ' Get the selected value of the DropDownList control.
      state = list.SelectedItem.Text
    
    Else
    
      ' Set the state to an empty string ("").
      state = ""
      
    End If
    
    Return state
  
  End Function

</script>

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

        <table cellspacing="10">
            
          <tr>
              
            <td>
                
              <asp:gridview id="StoresGridView" 
                datasourceid="StoresSqlDataSource" 
                autogeneratecolumns="false"
                autogenerateselectbutton="true"
                datakeynames="stor_id"
                onselectedindexchanged="StoresGridView_SelectedIndexChanged"   
                runat="server">
                
                <headerstyle backcolor="Blue"
                  forecolor="White"/>
                
                <columns>
                
                  <asp:boundfield datafield="stor_name"
                    headertext="Store Name"/>
                    
                  <asp:boundfield datafield="stor_address"
                    headertext="Address"/>
                    
                  <asp:boundfield datafield="city"
                    headertext="City"/>
                        
                  <asp:boundfield datafield="state"
                    headertext="State"/>
                    
                  <asp:boundfield datafield="zip"
                    headertext="ZIP Code"/>
                    
                </columns>
                
              </asp:gridview>
            
            </td>
                
            <td valign="top">
                
              <asp:detailsview id="StoresDetailView"
                datasourceid="StoresDetailsSqlDataSource"
                autogenerateinsertbutton="true"
                autogeneraterows="false" 
                datakeynames="stor_id"        
                gridlines="Both"
                oniteminserting="StoresDetailView_ItemInserting"
                oniteminserted="StoresDetailView_ItemInserted"    
                runat="server">
                
                <headerstyle backcolor="Navy"
                  forecolor="White"/>
                                    
                <fields>
                  
                  <asp:boundfield datafield="stor_id"
                    headertext="Store ID"/>
                    
                  <asp:boundfield datafield="stor_name"
                    headertext="Store Name"/>
                    
                  <asp:boundfield datafield="stor_address"
                    headertext="Address"/>
                    
                  <asp:boundfield datafield="city"
                    headertext="City"/>
                        
                  <asp:templatefield headertext="State">
                    <itemtemplate>
                      <%#Eval("state")%>
                    </itemtemplate>
                    <insertitemtemplate>
                      <asp:dropdownlist id="StateList"
                        datasourceid="StateSqlDataSource"
                        datatextfield="state" 
                        runat="server"/>
                    </insertitemtemplate>
                  </asp:templatefield>
                    
                  <asp:boundfield datafield="zip"
                    headertext="ZIP Code"/>
                    
                </fields>
                    
              </asp:detailsview>
            
            </td>
                
          </tr>
            
        </table>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        <asp:sqldatasource id="StoresSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]" 
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
            
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores]"
          insertcommand="INSERT INTO stores([stor_id], [stor_name], [stor_address], [city], [state], [zip]) VALUES (@stor_id, @stor_name, @stor_address, @city, @state, @zip)" 
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
        
        <!-- For this example, the states are retrieved from the  -->
        <!-- state field. For your application, you should use a  -->
        <!-- more complete source for the state values.           -->
        <asp:sqldatasource id="StateSqlDataSource"  
          selectcommand="SELECT Distinct [state] FROM [stores]"
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
            
      </form>
  </body>
</html>

설명

사용 된 InsertItemTemplate 항목에서 삽입 모드에 대해 표시 되는 사용자 지정 내용을 지정 하는 속성을 TemplateField 개체입니다. 삽입 모드에 있는 항목은 렌더링 하는 방법을 지정 하는 템플릿을 만들어 콘텐츠를 정의 합니다.

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

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

참고

일부 데이터 바인딩된 컨트롤 지원 같은 레코드를 삽입할 수 있도록 하는 데이터 바인딩된 컨트롤에 의해서만이 템플릿이 지원 되는 DetailsView 제어 합니다.

적용 대상

추가 정보