BoundField コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、BoundField クラスの新しいインスタンスを初期化します。通常、このコンストラクタは、動的に作成されたデータ バインド コントロールにフィールドを追加する場合に使用されます。
BoundField オブジェクトをデータ バインド コントロールに動的に追加するには、新しい BoundField オブジェクトを作成してそのプロパティを設定し、データ バインド コントロールのフィールド コレクションに追加します。たとえば、GridView コントロールを使用する場合は、BoundField オブジェクトを Columns コレクションに追加します。
![]() |
---|
フィールドはデータ バインド コントロールに動的に追加することもできますが、フィールドを静的に宣言しておき、適宜、表示または非表示にすることをお勧めします。すべてのフィールドを静的に宣言すると、親データ バインド コントロールのビューステートのサイズが小さくなります。 |

コンストラクタを使用して、BoundField オブジェクトを GridView コントロールに動的に追加するコード例を次に示します。
<%@ Page language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Dynamically generated field columns need to be created only ' the first time the page is loaded. If Not IsPostBack Then ' Dynamically create field columns to display the desired ' fields from the data source. ' Create a BoundField object to display a customer's company name. Dim nameBoundField As New BoundField() nameBoundField.DataField = "CompanyName" nameBoundField.HeaderText = "Company Name" ' Create a BoundField object to display a customer's city. Dim cityBoundField As New BoundField() cityBoundField.DataField = "City" cityBoundField.HeaderText = "City" ' Add the field columns to the ColumnFields collection of the ' GridView control. CustomersGridView.Columns.Add(nameBoundField) CustomersGridView.Columns.Add(cityBoundField) End If End Sub </script> <html> <body> <form runat="server"> <h3>BoundField Constructor Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Dynamically generated field columns need to be created only // the first time the page is loaded. if(!IsPostBack) { // Dynamically create field columns to display the desired // fields from the data source. // Create a BoundField object to display a customer's company name. BoundField nameBoundField = new BoundField(); nameBoundField.DataField = "CompanyName"; nameBoundField.HeaderText = "Company Name"; // Create a BoundField object to display a customer's city. BoundField cityBoundField = new BoundField(); cityBoundField.DataField = "City"; cityBoundField.HeaderText = "City"; // Add the field columns to the ColumnFields collection of the // GridView control. CustomersGridView.Columns.Add(nameBoundField); CustomersGridView.Columns.Add(cityBoundField); } } </script> <html> <body> <form runat="server"> <h3>BoundField Constructor Example</h3> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からBoundField コンストラクタを検索する場合は、下記のリンクをクリックしてください。

- BoundField コンストラクタのページへのリンク