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


プログラムによって、データ行を表す FormViewRow オブジェクトにアクセスするには、Row プロパティを使用します。データ行には、(CurrentMode プロパティで指定された) 現在のモード用に表示されるテンプレートに基づいて、異なるコンテンツが含まれます。現在のモードのテンプレートのコンテンツにのみアクセスできます。各モードで使用されるテンプレートを次の表に示します。
このプロパティは通常、プログラムによってデータ行を操作する必要がある場合 (カスタム コンテンツを追加する場合など) に使用されます。Row プロパティへの変更は、FormView コントロールがデータにバインドされた後に実行する必要があります。そうしないと、FormView コントロールによって変更が上書きされます。

Row プロパティを使用して、ItemCreated イベント中にデータ行のプロパティにアクセスする方法を次の例に示します。
<%@ page language="VB" %> <%@ import namespace="System.Data" %> <script runat="server"> Sub EmployeeFormView_ItemCreated(ByVal sender As Object, ByVal e As EventArgs) ' Use the Row property to retrieve the data row from ' the FormView control. Dim row As FormViewRow = EmployeeFormView.Row ' Get the data item bound to the FormView control. Dim rowView As DataRowView = CType(EmployeeFormView.DataItem, DataRowView) ' Set the ToolTip property of the data row. row.ToolTip = rowView("FirstName").ToString() & " " & _ rowView("LastName").ToString() End Sub </script> <html> <body> <form runat="server"> <h3>FormView Row Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" onitemcreated="EmployeeFormView_ItemCreated" runat="server"> <itemtemplate> <table> <tr> <td> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td> <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3> <%# Eval("Title") %> </td> </tr> </table> </itemtemplate> </asp:formview> <!-- 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], [Title], [PhotoPath] From [Employees]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ page language="C#" %> <%@ import namespace="System.Data" %> <script runat="server"> void EmployeeFormView_ItemCreated(Object sender, EventArgs e) { // Use the Row property to retrieve the data row from // the FormView control. FormViewRow row = EmployeeFormView.Row; // Get the data item bound to the FormView control. DataRowView rowView = (DataRowView)EmployeeFormView.DataItem; // Set the ToolTip property of the data row. row.ToolTip = rowView["FirstName"].ToString() + " " + rowView["LastName"].ToString(); } </script> <html> <body> <form runat="server"> <h3>FormView Row Example</h3> <asp:formview id="EmployeeFormView" datasourceid="EmployeeSource" allowpaging="true" datakeynames="EmployeeID" onitemcreated="EmployeeFormView_ItemCreated" runat="server"> <itemtemplate> <table> <tr> <td> <asp:image id="EmployeeImage" imageurl='<%# Eval("PhotoPath") %>' alternatetext='<%# Eval("LastName") %>' runat="server"/> </td> <td> <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3> <%# Eval("Title") %> </td> </tr> </table> </itemtemplate> </asp:formview> <!-- 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], [Title], [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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FormViewRow プロパティ



- FormView.Row プロパティのページへのリンク