ButtonField クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
データ バインド コントロールのボタンとして表示されるフィールドを表します。
public ref class ButtonField : System::Web::UI::WebControls::ButtonFieldBase
public class ButtonField : System.Web.UI.WebControls.ButtonFieldBase
type ButtonField = class
inherit ButtonFieldBase
Public Class ButtonField
Inherits ButtonFieldBase
- 継承
例
次のコード例では、 ButtonField オブジェクトを使用して、 GridView コントロール内のコマンド ボタンの列を表示する方法を示します。
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void CustomersGridView_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 = CustomersGridView.Rows[index];
TableCell contactName = selectedRow.Cells[1];
string contact = contactName.Text;
// Display the selected author.
Message.Text = "You selected " + contact + ".";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="CustomersGridView"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub CustomersGridView_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 = CustomersGridView.Rows(index)
Dim contactCell As TableCell = selectedRow.Cells(1)
Dim contact As String = contactCell.Text
' Display the selected author.
Message.Text = "You selected " & contact & "."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ButtonField Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"
AssociatedControlID="CustomersGridView"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
注釈
ButtonField クラスは、表示される各レコードのボタンを表示するために、データ バインド コントロール (GridViewやDetailsViewなど) によって使用されます。 ButtonField オブジェクトは、使用されているデータ バインド コントロールによって異なる方法で表示されます。 たとえば、 GridView コントロールは ButtonField オブジェクトを列として表示し、 DetailsView コントロールは行として表示します。
ボタン フィールド内のボタンをクリックすると、親データ バインド コントロールのコマンド イベントが発生します。 コマンド イベントのイベント ハンドラーを指定することで、コマンド ボタンがクリックされたときに実行するカスタム ルーチンを提供できます。
Note
GridView コントロールはRowCommand イベントを発生させ、DetailsView コントロールは ItemCommand イベントを発生させます。
コマンド イベントを発生させるレコードのインデックスを確認するには、データ バインド コントロールのコマンド イベントに渡されるイベント引数の CommandArgument プロパティを使用します。 ButtonField クラスは、CommandArgument プロパティに適切なインデックス値を自動的に設定します。
表示するボタンの種類を指定するには、 ButtonType プロパティを使用します。 リンクまたはコマンド ボタンを表示する場合は、 Text プロパティを使用して、ボタンに表示するキャプションを指定します。
Note
Text プロパティを設定すると、ButtonField内のすべてのボタンが同じキャプションを共有します。
または、 ButtonField オブジェクトをデータ ソース内のフィールドにバインドすることもできます。 これにより、 ButtonField オブジェクト内のボタンに対して異なるキャプションを表示できます。 指定したフィールド内の値は、ボタンのテキスト キャプションに使用されます。 DataTextField プロパティを設定して、ButtonField オブジェクトをデータ ソース内のフィールドにバインドします。
イメージ ボタンを表示するときは、 ImageUrl プロパティを使用して、 ButtonField オブジェクト内のボタンに表示するイメージを指定します。
Note
ButtonField オブジェクト内のすべてのボタンは同じイメージを共有します。
ButtonField プロパティを Visible に設定することで、データ バインド コントロール内のfalse オブジェクトを非表示にすることができます。
ButtonField オブジェクトを使用すると、ヘッダーセクションとフッターセクションをカスタマイズできます。 ヘッダーまたはフッター セクションにキャプションを表示するには、それぞれ HeaderText プロパティまたは FooterText プロパティを設定します。 ヘッダー セクションにテキストを表示する代わりに、 HeaderImageUrl プロパティを設定して画像を表示できます。
ButtonField オブジェクトのヘッダー セクションを非表示にするには、ShowHeader プロパティを false に設定します。
Note
一部のデータ バインド コントロール ( GridView コントロールなど) では、コントロールのヘッダー セクション全体のみを表示または非表示にすることができます。 これらのデータ バインド コントロールは、個々のボタン フィールドの ShowHeader プロパティをサポートしていません。 データ バインド コントロールのヘッダー セクション全体を表示または非表示にするには (使用可能な場合)、コントロールの ShowHeader プロパティを使用します。
また、フィールドのさまざまな部分のスタイル プロパティを設定して、 ButtonField オブジェクトの外観 (フォントの色、背景色など) をカスタマイズすることもできます。 次の表に、さまざまなスタイル プロパティを示します。
| Style プロパティ | のスタイル設定 |
|---|---|
| ControlStyle | ButtonFieldの子 Web サーバー コントロール。 |
| FooterStyle | ButtonFieldのフッター セクション。 |
| HeaderStyle | ButtonFieldのヘッダー セクション。 |
| ItemStyle | ButtonField内のデータ項目。 |
コンストラクター
| 名前 | 説明 |
|---|---|
| ButtonField() |
ButtonField クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| AccessibleHeaderText |
一部のコントロールの |
| ButtonType |
ボタン フィールドに表示するボタンの種類を取得または設定します。 (継承元 ButtonFieldBase) |
| CausesValidation |
ButtonFieldBase オブジェクト内のボタンがクリックされたときに検証を実行するかどうかを示す値を取得または設定します。 (継承元 ButtonFieldBase) |
| CommandName |
ButtonField オブジェクト内のボタンがクリックされたときに実行するアクションを表す文字列を取得または設定します。 |
| Control |
DataControlField オブジェクトが関連付けられているデータ コントロールへの参照を取得します。 (継承元 DataControlField) |
| ControlStyle |
DataControlField オブジェクトに含まれる Web サーバー コントロールのスタイルを取得します。 (継承元 DataControlField) |
| DataTextField |
Text オブジェクトによってレンダリングされるButton コントロールのButtonField プロパティに値がバインドされるデータ フィールドの名前を取得または設定します。 |
| DataTextFormatString |
フィールドの値の表示形式を指定する文字列を取得または設定します。 |
| DesignMode |
データ コントロール フィールドがデザイン時環境で現在表示されているかどうかを示す値を取得します。 (継承元 DataControlField) |
| FooterStyle |
データ コントロール フィールドのフッターのスタイルを取得または設定します。 (継承元 DataControlField) |
| FooterText |
データ コントロール フィールドのフッター項目に表示されるテキストを取得または設定します。 (継承元 DataControlField) |
| HeaderImageUrl |
データ コントロール フィールドのヘッダー項目に表示されるイメージの URL を取得または設定します。 (継承元 DataControlField) |
| HeaderStyle |
データ コントロール フィールドのヘッダーのスタイルを取得または設定します。 (継承元 DataControlField) |
| HeaderText |
データ コントロール フィールドのヘッダー項目に表示されるテキストを取得または設定します。 (継承元 DataControlField) |
| ImageUrl |
ButtonField オブジェクト内の各ボタンに表示するイメージを取得または設定します。 |
| InsertVisible |
親データ バインド コントロールが挿入モードのときに、 DataControlField オブジェクトが表示されるかどうかを示す値を取得します。 (継承元 DataControlField) |
| IsTrackingViewState |
DataControlField オブジェクトがビュー ステートへの変更を保存しているかどうかを示す値を取得します。 (継承元 DataControlField) |
| ItemStyle |
データ コントロール フィールドによって表示されるテキスト ベースのコンテンツのスタイルを取得します。 (継承元 DataControlField) |
| ShowHeader |
ヘッダー セクションが ButtonFieldBase オブジェクトに表示されるかどうかを示す値を取得または設定します。 (継承元 ButtonFieldBase) |
| SortExpression |
データ を並べ替えるためにデータ ソース コントロールによって使用される並べ替え式を取得または設定します。 (継承元 DataControlField) |
| Text |
ButtonField オブジェクトの各ボタンに表示される静的キャプションを取得または設定します。 |
| ValidateRequestMode |
コントロールがクライアント入力を検証するかどうかを指定する値を取得または設定します。 (継承元 DataControlField) |
| ValidationGroup |
ButtonFieldBase オブジェクト内のボタンがクリックされたときに検証する検証コントロールのグループの名前を取得または設定します。 (継承元 ButtonFieldBase) |
| ViewState |
同じページに対する複数の要求にわたって、 DataControlField オブジェクトのビュー ステートを保存および復元できる状態情報のディクショナリを取得します。 (継承元 DataControlField) |
| Visible |
データ コントロール フィールドがレンダリングされるかどうかを示す値を取得または設定します。 (継承元 DataControlField) |
メソッド
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IDataSourceViewSchemaAccessor.DataSourceViewSchema |
この DataControlField オブジェクトに関連付けられているスキーマを取得または設定します。 (継承元 DataControlField) |
| IStateManager.IsTrackingViewState |
DataControlField オブジェクトがビュー ステートへの変更を保存しているかどうかを示す値を取得します。 (継承元 DataControlField) |
| IStateManager.LoadViewState(Object) |
データ コントロール フィールドの以前に保存したビューステートを復元します。 (継承元 DataControlField) |
| IStateManager.SaveViewState() |
ページがサーバーにポストバックされてから、 DataControlField ビューステートに加えられた変更を保存します。 (継承元 DataControlField) |
| IStateManager.TrackViewState() |
DataControlField オブジェクトがビューステートの変更を追跡し、コントロールのViewState プロパティに格納し、同じページに対する要求間で永続化できるようにします。 (継承元 DataControlField) |