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


DataKeyNames プロパティが設定されている場合、FormView コントロールは、現在のレコードの DataKeyNames プロパティにリストされているフィールド (複数可) のキーと値のペアを格納する DataKey オブジェクトを自動的に作成します。DataKey オブジェクトは、現在のレコードの 1 つ以上の主キーを表し、DataKey プロパティに格納されます。DataKey より簡単な方法として、プロパティを使用してデータ キー値にアクセスする代わりに SelectedValue プロパティを使用できます。
![]() |
---|
DataKeyNames プロパティに複数のフィールドがリストされている場合、このプロパティは、リストの最初の値を返します。 |

SelectedValue プロパティを使用して、キー フィールドの値を確認する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub EmployeeFormView_ItemCreated(ByVal sender As Object, ByVal e As EventArgs) MessageLabel.Text = "The key value is " & EmployeeFormView.SelectedValue.ToString() & "." End Sub </script> <html> <body> <form runat="server"> <h3>FormView SelectedValue 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> <br/><br/> <asp:label id="MessageLabel" forecolor="Red" 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], [Title], [PhotoPath] From [Employees]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void EmployeeFormView_ItemCreated(Object sender, EventArgs e) { MessageLabel.Text = "The key value is " + EmployeeFormView.SelectedValue.ToString() + "."; } </script> <html> <body> <form runat="server"> <h3>FormView SelectedValue 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> <br/><br/> <asp:label id="MessageLabel" forecolor="Red" 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], [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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFormView.SelectedValue プロパティを検索する場合は、下記のリンクをクリックしてください。

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