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

Dim instance As ButtonField Dim value As String value = instance.DataTextField instance.DataTextField = value
/** @property */ public String get_DataTextField () /** @property */ public void set_DataTextField (String value)
ButtonField にバインドするフィールドの名前。既定値は空の文字列 ("") です。この値は DataTextField プロパティが設定されていないことを示します。

ButtonField オブジェクトの ButtonType プロパティに Button 値または Link 値を設定すると、DataTextField プロパティを使用して、ButtonField オブジェクトにバインドするフィールドの名前を指定できます。フィールドの値はボタンのテキストとして ButtonField オブジェクトに表示されます。また、オプションの DataTextFormatString プロパティを設定すると、表示されるテキストの書式を指定できます。
DataTextField プロパティを使用して ButtonField オブジェクトをデータ ソースのフィールドにバインドする代わりに、Text プロパティを使用して ButtonField オブジェクトのボタンに静的テキストを表示できます。Text プロパティを使用すると、各ボタンは同じキャプションを共有します。
![]() |
---|
DataTextField プロパティと Text プロパティの両方が設定されている場合は、DataTextField プロパティが優先されます。 |

次のコード例では、DataTextField プロパティを使用して、GridView コントロールの ButtonField 列に表示するフィールドを指定する方法を示します。
<%@ Page language="VB" %> <script runat="server"> Sub AuthorsGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' If multiple ButtonField column fields are used, use the ' CommandName property to determine which button was clicked. If e.CommandName = "Select" Then ' Convert the row index stored in the CommandArgument ' property to an Integer. Dim index As Integer = Convert.ToInt32(e.CommandArgument) ' Get the last name of the selected author from the appropriate ' cell in the GridView control. Dim selectedRow As GridViewRow = AuthorsGridView.Rows(index) Dim lastNameCell As TableCell = selectedRow.Cells(1) Dim lastName As String = lastNameCell.Text ' Display the selected author. Message.Text = "You selected " & lastName & "." End If End Sub </script> <html> <body> <form runat="server"> <h3>ButtonField DataTextField Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <!-- Set the DataTextField property of the ButtonField --> <!-- declaratively. Set the DataTextFormatString --> <!-- property to apply special formatting to the text. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" onrowcommand="AuthorsGridView_RowCommand" runat="server"> <columns> <asp:buttonfield buttontype="Link" commandname="Select" headertext="Select Author" datatextfield="au_lname" datatextformatstring="[{0}]" text="Select"/> <asp:boundfield datafield="au_fname" headertext="First Name"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname] FROM [authors]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void AuthorsGridView_RowCommand(Object sender, GridViewCommandEventArgs e) { // If multiple ButtonField column fields are used, use the // CommandName property to determine which button was clicked. if(e.CommandName=="Select") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the last name of the selected author from the appropriate // cell in the GridView control. GridViewRow selectedRow = AuthorsGridView.Rows[index]; TableCell lastNameCell = selectedRow.Cells[1]; string lastName = lastNameCell.Text; // Display the selected author. Message.Text = "You selected " + lastName + "."; } } </script> <html> <body> <form runat="server"> <h3>ButtonField DataTextField Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <!-- Set the DataTextField property of the ButtonField --> <!-- declaratively. Set the DataTextFormatString --> <!-- property to apply special formatting to the text. --> <asp:gridview id="AuthorsGridView" datasourceid="AuthorsSqlDataSource" autogeneratecolumns="false" onrowcommand="AuthorsGridView_RowCommand" runat="server"> <columns> <asp:buttonfield buttontype="Link" commandname="Select" headertext="Select Author" datatextfield="au_lname" datatextformatstring="[{0}]" text="Select"/> <asp:boundfield datafield="au_fname" headertext="First Name"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Pubs sample database. --> <asp:sqldatasource id="AuthorsSqlDataSource" selectcommand="SELECT [au_lname], [au_fname] FROM [authors]" connectionstring="server=localhost;database=pubs;integrated security=SSPI" 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に収録されているすべての辞書からButtonField.DataTextField プロパティを検索する場合は、下記のリンクをクリックしてください。

- ButtonField.DataTextField プロパティのページへのリンク