ButtonType 列挙体とは? わかりやすく解説

ButtonType 列挙体

メモ : この列挙体は、.NET Framework version 2.0新しく追加されたものです。

Web フォーム ページ表示できるさまざまな種類ボタン指定します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

public enum ButtonType
public enum class ButtonType
public enum ButtonType
public enum ButtonType
メンバメンバ
解説解説
使用例使用例

ButtonType 列挙体を使用して、GridView コントロールの ButtonField フィールド列にリンク ボタン表示するように指定する方法次の例に示しますButtonField オブジェクトButtonType プロパティが、宣言によって ButtonType.Link設定されます。

<%@ 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
  
  Sub AuthorsGridView_RowCreated(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)
    
    ' The GridViewCommandEventArgs class does not contain a 
    ' property that indicates which row's command button was
    ' clicked. To identify which row contains the button 
    ' clicked, use the button's CommandArgument property by 
    ' setting it to the row's index.
    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Retrieve the button control from the first column.
      ' Because the ButtonType property of the column field
      ' is set to ButtonType.Link, the button control must be
      ' cast to a LinkButton. If you specify a different button
      ' type, you must cast the button control to the appropriate
      ' button type.
      Dim selectButton As LinkButton = CType(e.Row.Cells(0).Controls(0),
 LinkButton)
            
      ' Set the LinkButton's CommandArgument property with the
      ' row's index.
      selectButton.CommandArgument = e.Row.RowIndex.ToString()
      
    End If

  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonType Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                    
      <!-- Populate the Columns collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand"
 
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" commandname="Select"
 text="Select"/>
          <asp:boundfield datafield="au_lname"
 headertext="au_lname"/>
          <asp:boundfield datafield="au_fname"
 headertext="au_fname"/>
                
        </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 + ".";
      
    }
    
  }
  
  void AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs
 e)
  {
    
    // The GridViewCommandEventArgs class does not contain a 
    // property that indicates which row's command button was
    // clicked. To identify which row contains the button 
    // clicked, use the button's CommandArgument property by 
    // setting it to the row's index.
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
    
      // Retrieve the button control from the first column.
      // Because the ButtonType property of the column field
      // is set to ButtonType.Link, the button control must be
      // cast to a LinkButton. If you specify a different button
      // type, you must cast the button control to the appropriate
      // button type.
      LinkButton selectButton = (LinkButton)e.Row.Cells[0].Controls[0];
            
      // Set the LinkButton's CommandArgument property with the
      // row's index.
      selectButton.CommandArgument = e.Row.RowIndex.ToString();
      
    }

  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>ButtonType Example</h3>
      
      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
                    
      <!-- Populate the Fields collection declaratively. -->
      <asp:gridview id="AuthorsGridView" 
        datasourceid="AuthorsSqlDataSource" 
        autogeneratecolumns="false"
        onrowcommand="AuthorsGridView_RowCommand" 
        runat="server">
                
        <columns>
                
          <asp:buttonfield buttontype="Link" commandname="Select"
 text="Select"/>
          <asp:boundfield datafield="au_lname" headertext="au_lname"/>
          <asp:boundfield datafield="au_fname" headertext="au_fname"/>
                
        </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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Web.UI.WebControls 名前空間
ButtonFieldBase.ButtonType プロパティ
ButtonField クラス
ButtonFieldBase クラス
GridView



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ButtonType 列挙体」の関連用語

ButtonType 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ButtonType 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS