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


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

このコンストラクタを使用して、ImageField オブジェクトを GridView コントロールの Columns コレクションに動的に追加する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Dynamically create a GridView control. Dim employeesView As GridView = New GridView() employeesView.ID = "EmployeesGrid" employeesView.AutoGenerateColumns = False employeesView.DataSourceID = "EmployeeSource" ' Dynamically create field columns to display the desired ' fields from the data source. ' Create an ImageField object to display an employee's photo. Dim photoImageField As ImageField = New ImageField() photoImageField.DataImageUrlField = "PhotoPath" photoImageField.AlternateText = "Employee Photo" photoImageField.NullDisplayText = "No image on file." photoImageField.HeaderText = "Photo" photoImageField.ReadOnly = True ' Create a BoundField object to display an employee's last name. Dim lastNameBoundField As BoundField = New BoundField() lastNameBoundField.DataField = "LastName" lastNameBoundField.HeaderText = "Last Name" ' Create a BoundField object to display an employee's first name. Dim firstNameBoundField As BoundField = New BoundField() firstNameBoundField.DataField = "FirstName" firstNameBoundField.HeaderText = "First Name" ' Add the field columns to the Fields collection of the ' GridView control. employeesView.Columns.Add(photoImageField) employeesView.Columns.Add(lastNameBoundField) employeesView.Columns.Add(firstNameBoundField) ' Add the GridView control to the Controls collection ' of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(employeesView) End If End Sub </script> <html> <body> <form runat="server"> <h3>ImageField 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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { // Dynamically create a GridView control. GridView employeesView = new GridView(); employeesView.ID = "EmployeesGrid"; employeesView.AutoGenerateColumns = false; employeesView.DataSourceID = "EmployeeSource"; // Dynamically create field columns to display the desired // fields from the data source. // Create an ImageField object to display an employee's photo. ImageField photoImageField = new ImageField(); photoImageField.DataImageUrlField = "PhotoPath"; photoImageField.AlternateText = "Employee Photo"; photoImageField.NullDisplayText = "No image on file."; photoImageField.HeaderText = "Photo"; photoImageField.ReadOnly = true; // Create a BoundField object to display an employee's last name. BoundField lastNameBoundField = new BoundField(); lastNameBoundField.DataField = "LastName"; lastNameBoundField.HeaderText = "Last Name"; // Create a BoundField object to display an employee's first name. BoundField firstNameBoundField = new BoundField(); firstNameBoundField.DataField = "FirstName"; firstNameBoundField.HeaderText = "First Name"; // Add the field columns to the Fields collection of the // GridView control. employeesView.Columns.Add(photoImageField); employeesView.Columns.Add(lastNameBoundField); employeesView.Columns.Add(firstNameBoundField); // Add the GridView control to the Controls collection // of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(employeesView); } } </script> <html> <body> <form runat="server"> <h3>ImageField 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="EmployeeSource" selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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