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

DetailsView コントロールの明示的に宣言された行フィールドをすべて格納している DataControlFieldCollection。

DetailsView コントロールの行フィールドを明示的に宣言すると、それらの行フィールドは Fields プロパティ (コレクション) に格納されます。Fields コレクションを使用すると、明示的に宣言された行のコレクションをプログラムによって管理することもできます。
![]() |
---|
明示的に宣言された行フィールドは、自動的に生成された行フィールドと共に使用できます。この両方の行フィールドが使用される場合は、明示的に宣言された行フィールドが表示された後で、自動的に生成された行フィールドが表示されます。自動的に生成された行フィールドは、Fields コレクションに追加されません。 |
行フィールドの種類によって、コントロール内の行の機能は異なります。Fields コレクションで使用できる、行フィールドのさまざまな種類の一覧を次の表に示します。
BoundField | |
ButtonField | DetailsView コントロールにコマンド ボタンを表示します。これにより、Add ボタンや Remove ボタンなどのカスタム ボタン コントロールを行に表示できます。 |
CheckBoxField | DetailsView コントロールにチェック ボックスを表示します。通常、この種類の行フィールドは、フィールドにブール値を表示する場合に使用されます。 |
CommandField | 編集、挿入、または削除の操作を実行するための組み込みのコマンド ボタンを DetailsView コントロールに表示します。 |
HyperLinkField | データ ソース内のフィールドの値をハイパーリンクとして表示します。この種類の行フィールドを使用すると、2 番目のフィールドをハイパーリンクの URL にバインドできます。 |
ImageField | |
TemplateField | 指定されたテンプレートに従って、ユーザー定義の行の内容を DetailsView コントロールに表示します。この種類の行フィールドを使用すると、カスタム行フィールドを作成できます。 |
DetailsView コントロールの行フィールドを明示的に宣言するには、最初に AutoGenerateRows プロパティを false に設定します。次に、DetailsView コントロールの開始タグと終了タグの間に <Fields> の開始タグと終了タグを追加します。最後に、<Fields> の開始タグと終了タグの間に組み込む行フィールドをリストします。行フィールドが、Fields コレクションに示される順序で DetailsView コントロールに表示されます。
行フィールドはプログラムによって Fields コレクションに追加できますが、行フィールドを宣言によって DetailsView コントロールにリストし、各行フィールドの Visible プロパティを使用して行フィールドの表示/非表示を切り替えるほうが簡単です。
行フィールドの Visible プロパティが false に設定されている場合、その行は DetailsView コントロールに表示されず、行のデータはクライアントへのラウンド トリップを行いません。表示されない行のデータをラウンド トリップさせる場合は、そのフィールド名を DataKeyNames プロパティに追加します。

宣言によって行フィールドを DetailsView コントロールの Fields コレクションに追加する方法のコード例を次に示します。
<%@ Page language="VB" %> <script runat="server"> </script> <html> <body> <form id="Form1" runat="server"> <h3>DetailsView Fields Example</h3> <asp:detailsview id="CustomerDetailView" datasourceid="DetailsViewSource" datakeynames="CustomerID" AutoGenerateRows="false" allowpaging="true" runat="server"> <Fields> <asp:BoundField DataField="CompanyName" HeaderText="Company Name"/> <asp:BoundField DataField="City" HeaderText="City"/> </Fields> </asp:detailsview> <!-- 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="DetailsViewSource" runat="server" ConnectionString= "<%$ ConnectionStrings:NorthWindConnectionString%>" InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" SelectCommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"> </asp:SqlDataSource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> </script> <html> <body> <form id="Form1" runat="server"> <h3>DetailsView Fields Example</h3> <asp:detailsview id="CustomerDetailView" datasourceid="DetailsViewSource" datakeynames="CustomerID" AutoGenerateRows="false" allowpaging="true" runat="server"> <Fields> <asp:BoundField DataField="CompanyName" HeaderText="Company Name"/> <asp:BoundField DataField="City" HeaderText="City"/> </Fields> </asp:detailsview> <!-- 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="DetailsViewSource" runat="server" ConnectionString= "<%$ ConnectionStrings:NorthWindConnectionString%>" InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)" SelectCommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"> </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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DetailsView.Fields プロパティのページへのリンク