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

サーバー コントロールの名前付けコンテナ。

ASP.NET Web アプリケーションの各ページには、コントロールの階層構造が含まれています。この階層構造は、コントロールがユーザーから参照できる UI を生成するかどうかに依存しません。特定のコントロールの名前付けコンテナは、INamingContainer インターフェイスを実装する階層構造において、そのコントロールの上位にある親コントロールです。このインターフェイスを実装するサーバー コントロールは、子サーバー コントロールの ID プロパティ値の一意の名前空間を作成します。
サーバー コントロールの一意の名前空間の作成は、Repeater サーバー コントロールおよび DataList サーバー コントロールなどの Web サーバー コントロールのリストに対してデータを連結するときに特に重要です。データ ソースの複数のエントリが、連続しているコントロールの子サーバー コントロールの複数インスタンスを作成する場合、名前付けコンテナは子コントロールの各インスタンスが競合しない UniqueID プロパティ値を確実に持つように設定します。ページに対する既定の名前付けコンテナは、そのページが要求されたときに生成された Page クラスのインスタンスです。
このプロパティを使用して、特定のサーバー コントロールがある名前付けコンテナを確認できます。

NamingContainer プロパティを使用する例を次に示します。
<%@ Import Namespace = "System.Data" %> <html> <head> <script language="VB" runat="server"> ' Build the DataSource. Function CreateDataSource() As ICollection Dim myDataTable As New DataTable() Dim myDataRow As DataRow myDataTable.Columns.Add(New DataColumn("EmployeeName", GetType(String))) Dim i As Integer For i = 0 To 9 myDataRow = myDataTable.NewRow() myDataRow(0) = "somename" + i.ToString() myDataTable.Rows.Add(myDataRow) Next i Dim myDataView As New DataView(myDataTable) Return myDataView End Function Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then ' Bind 'DataView' to the DataSource. myDataList.DataSource = CreateDataSource() myDataList.DataBind() End If ' Attach EventHandler for SelectedIndexChanged event. AddHandler myDataList.SelectedIndexChanged, AddressOf selectedItemChanged End Sub ' Handler function for 'SelectedIndexChanged' event. Sub selectedItemChanged(sender As Object, e As EventArgs) Dim myCurrentItem As DataListItem = myDataList.SelectedItem Dim myNamingContainer As Control = myCurrentItem.Controls(0).NamingContainer ' Display the NamingContainer. myLabel1.Text = "The NamingContainer is : " + myNamingContainer.UniqueID ' Display the UniqueID. myLabel2.Text = "The UniqueID is : " + CType(myCurrentItem.Controls(0), Control).UniqueID End Sub </script> </head> <body> <form runat="server" ID="Form1"> <h3> Control NamingContainer Example </h3> <h4> Click an item to view it's Naming Container and UniqueID </h4> <asp:Label ID="myLabel1" Runat="server"></asp:Label> <br> <asp:Label ID="myLabel2" Runat="server"></asp:Label> <br> <asp:DataList id="myDataList" runat="server" BorderColor="black"> <HeaderStyle BackColor="#aaaadd"></HeaderStyle> <SelectedItemStyle BackColor="lightgreen"></SelectedItemStyle> <HeaderTemplate> EmployeeName </HeaderTemplate> <ItemTemplate> <asp:LinkButton id="button1" Text='<%# DataBinder.Eval(Container.DataItem, "EmployeeName") %>' CommandName="select" runat="server" /> </ItemTemplate> </asp:DataList> </form> </body> </html>
<% @ Import Namespace = "System.Data" %> <html> <head> <script language="C#" runat="server"> // Build the DataSource. ICollection CreateDataSource() { DataTable myDataTable = new DataTable(); DataRow myDataRow; myDataTable.Columns.Add(new DataColumn("EmployeeName", typeof(string))); for (int i = 0; i < 10; i++) { myDataRow = myDataTable.NewRow(); myDataRow[0] = "somename" + i.ToString(); myDataTable.Rows.Add(myDataRow); } DataView myDataView = new DataView(myDataTable); return myDataView; } void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { // Bind 'DataView' to the DataSource. myDataList.DataSource = CreateDataSource(); myDataList.DataBind(); } // Attach EventHandler for SelectedIndexChanged event. myDataList.SelectedIndexChanged += new EventHandler(selectedItemChanged); } // Handler function for 'SelectedIndexChanged' event. void selectedItemChanged(Object sender,EventArgs e) { DataListItem myCurrentItem = myDataList.SelectedItem; Control myNamingContainer = myCurrentItem.Controls[0].NamingContainer; // Display the NamingContainer. myLabel1.Text = "The NamingContainer is : " + myNamingContainer.UniqueID; // Display the UniqueID. myLabel2.Text = "The UniqueID is : " + ((Control)(myCurrentItem.Controls[0])).UniqueID; } </script> </head> <body> <form runat="server" ID="Form1"> <h3> Control NamingContainer Example </h3> <h4> Click an item to view it's Naming Container and UniqueID </h4> <asp:Label ID="myLabel1" Runat="server"></asp:Label> <br> <asp:Label ID="myLabel2" Runat="server"></asp:Label> <br> <asp:DataList id="myDataList" runat="server" BorderColor="black"> <HeaderStyle BackColor="#aaaadd"></HeaderStyle> <SelectedItemStyle BackColor="lightgreen"></SelectedItemStyle> <HeaderTemplate> EmployeeName </HeaderTemplate> <ItemTemplate> <asp:LinkButton id="button1" Text='<%# DataBinder.Eval(Container.DataItem, "EmployeeName") %>' CommandName="select" runat="server" /> </ItemTemplate> </asp:DataList> </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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からControl.NamingContainer プロパティを検索する場合は、下記のリンクをクリックしてください。

- Control.NamingContainer プロパティのページへのリンク