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


このコンストラクタを使用して、GridView クラスの新しいインスタンスを初期化します。GridView コントロールをページに動的に追加するには、新しい GridView オブジェクトを作成してそのプロパティを設定し、コンテナ コントロール (PlaceHolder など) の Control.Controls コレクションに追加します。

コンストラクタを使用して、ページに GridView コントロールを動的に追加する方法を次のコード例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new GridView object. Dim customersGridView As New GridView() ' Set the GridView object's properties. customersGridView.ID = "CustomersGridView" customersGridView.DataSourceID = "CustomersSource" customersGridView.AutoGenerateColumns = True ' Add the GridView object to the Controls collection ' of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(customersGridView) End Sub </script> <html> <body> <form runat="server"> <h3>GridView Constructor Example</h3> <asp:placeholder id="GridViewPlaceHolder" runat="Server"/> <!-- 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="CustomersSource" selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create a new GridView object. GridView customersGridView = new GridView(); // Set the GridView object's properties. customersGridView.ID = "CustomersGridView"; customersGridView.DataSourceID = "CustomersSource"; customersGridView.AutoGenerateColumns = true; // Add the GridView object to the Controls collection // of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(customersGridView); } </script> <html> <body> <form runat="server"> <h3>GridView Constructor Example</h3> <asp:placeholder id="GridViewPlaceHolder" runat="Server"/> <!-- 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="CustomersSource" selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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