TemplateField.EditItemTemplate プロパティ
アセンブリ: System.Web (system.web.dll 内)

<TemplateContainerAttribute(GetType(IDataItemContainer), BindingDirection.TwoWay)> _ Public Overridable Property EditItemTemplate As ITemplate
Dim instance As TemplateField Dim value As ITemplate value = instance.EditItemTemplate instance.EditItemTemplate = value
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)] public virtual ITemplate EditItemTemplate { get; set; }
[TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection::TwoWay)] public: virtual property ITemplate^ EditItemTemplate { ITemplate^ get (); void set (ITemplate^ value); }
/** @property */ public ITemplate get_EditItemTemplate () /** @property */ public void set_EditItemTemplate (ITemplate value)
public function get EditItemTemplate () : ITemplate public function set EditItemTemplate (value : ITemplate)
TemplateField の編集モードの項目を表示するときに使用するテンプレートを格納している System.Web.UI.ITemplate 実装オブジェクト。既定値は null 参照 (Visual Basic では Nothing) です。このプロパティが設定されていないことを示します。

EditItemTemplate プロパティを使用して、TemplateField オブジェクトの編集モードの項目に表示するカスタムの内容を指定します。編集モードの項目を表示する方法を指定するテンプレートを作成して、内容を定義します。EditItemTemplate プロパティには、通常、データ ソース内の値を変更するためのユーザー向け入力コントロールが格納されます。
テンプレートを指定するには、まず、<TemplateField> 要素の開始タグと終了タグの間に <EditItemTemplate> の開始タグと終了タグを配置します。次に、開始 <EditItemTemplate> タグと終了 <EditItemTemplate> タグの間にカスタムの内容を追加します。内容は、簡単なプレーンテキストとしたり、テンプレートに他のコントロールを埋め込んで複雑にしたりできます。
テンプレートで定義されたコントロールにプログラムからアクセスするには、まず、そのコントロールが、データ バインド コントロールの、どの TableCell オブジェクトに含まれるかを確認します。次に、TableCell オブジェクトの Controls コレクションを使用してコントロールにアクセスします。コントロールに ID プロパティが指定されている場合は、TableCell オブジェクトの FindControl メソッドを使用してコントロールを検索することもできます。

EditItemTemplate プロパティを使用して、GridView コントロールの TemplateField フィールド列に表示される編集モードの項目のカスタム テンプレートを作成するコード例を次に示します。このテンプレートには、ユーザーが値フィールドに必ず値を入力するようにするための検証サーバー コントロールが含まれています。
<%@ Page language="VB" %> <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> <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="C#" %> <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> <body> <form 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TemplateField.EditItemTemplate プロパティのページへのリンク