DataGridCommandEventArgs.CommandSource プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridCommandEventArgs.CommandSource プロパティの意味・解説 

DataGridCommandEventArgs.CommandSource プロパティ

コマンドソース取得します

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

Dim instance As DataGridCommandEventArgs
Dim value As Object

value = instance.CommandSource
public Object CommandSource { get; }
public:
property Object^ CommandSource {
    Object^ get ();
}
/** @property */
public Object get_CommandSource ()

プロパティ
コマンドソース

解説解説
使用例使用例

CommandSource プロパティ使用してコマンドソース確認する方法次のコード例示します

<%@ page language="VB" %>
<%@ import namespace="System.Data"
 %>
<%@ import namespace="System.Data.SqlClient"
 %>

<script runat="server">

  Sub Page_Load(ByVal sender As
 Object, ByVal e As EventArgs)
  
    ' Call the BindGrid helper method to bind the
    ' DataGrid control to the data source the first
    ' time the page is loaded.
    If Not IsPostBack Then
    
      BindGrid()
    
    End If
    
  End Sub
  
  Sub BindGrid()
  
    ' Declare the connection string and query string.
    ' This example uses Microsoft SQL Server and connects
    ' to the Northwind sample database.
    Dim connectionString As String
 = "server=localhost;database=NorthWind;Integrated Security=SSPI"
    Dim queryString As String
 = "Select [FirstName],[LastName],[Title] From [Employees]"
    
    ' Run the query and display the results.
    Dim ds As DataSet = RunQuery(connectionString,
 queryString)
    If ds IsNot Nothing Then
 
      ItemsGrid.DataSource = ds
      ItemsGrid.DataBind()
      Message.Text = ""
    
    Else
    
      Message.Text = "No records found."
    
    End If
      
  End Sub

  Function RunQuery(ByVal connectionString
 As String, ByVal queryString
 As String) As DataSet
  
    Dim connection As New
 SqlConnection(connectionString)
    Dim adapter As SqlDataAdapter
    Dim ds As DataSet
    
    Try

      ' Run the query and create the DataSet object.
      ds = New DataSet()
      adapter = New SqlDataAdapter(queryString, connection)
      adapter.Fill(ds)
    
    Catch ex As Exception
   
      ' Display an error message.
      Message.Text = "Unable to query data source."
      ds = Nothing
    
    Finally
    
      Connection.Close()
    
    End Try
    
    Return ds
  
  End Function

  Sub ItemsGrid_ItemCommand(ByVal sender As
 Object, ByVal e As DataGridCommandEventArgs)
  
    ' Use the CommandSource property to retrieve the LinkButton
    ' control that raised the event.
    Dim selectButton As LinkButton = CType(e.CommandSource,
 LinkButton)

    ' Display the desciption for the job title.
    Message.Text = selectButton.Text & " - "
    
    Select Case (selectButton.Text)
    
      Case "Sales Representative"
        Message.Text &= "Sells products to customers."

      Case "Vice President, Sales"
        Message.Text &= "Manages the sales division."

      Case "Sales Manager"
        Message.Text &= "Manages a sales team."

      Case "Inside Sales Coordinator"
        Message.Text &= "Coordinates cross team communications."

      Case Else
        Message.Text &= "To be determined."
    
    End Select
    
  End Sub
  
</script>

<html>
  <body>
    <form runat="server">

      <h3>DataGridCommandEventArgs CommandSource Example</h3>

      <asp:datagrid
        id="ItemsGrid"
        autogeneratecolumns="false"
        onitemcommand="ItemsGrid_ItemCommand"  
        runat="server">

          <columns>
          
            <asp:BoundColumn DataField="FirstName"
              headertext="First Name"/>
            <asp:BoundColumn DataField="LastName"
              headertext="Last Name"/>
            <asp:buttoncolumn buttontype="LinkButton"
              datatextfield="Title"
              headertext="Title"/> 
          
          </columns>
        
      </asp:datagrid>
      
      <br/><br/>
      
      <asp:label id="Message" 
        runat="server"/>

    </form>
  </body>
</html>
<%@ page language="C#" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
    // Call the BindGrid helper method to bind the
    // DataGrid control to the data source the first
    // time the page is loaded.
    if(!IsPostBack)
    {
      BindGrid();
    }
  }
  
  void BindGrid()
  {
    // Declare the connection string and query string.
    // This example uses Microsoft SQL Server and connects
    // to the Northwind sample database.
    String connectionString = "server=localhost;database=NorthWind;Integrated
 Security=SSPI";
    String queryString = "Select [FirstName],[LastName],[Title] From [Employees]";
    
    // Run the query and display the results.
    DataSet ds = RunQuery(connectionString, queryString);
    if(ds != null)
    {
      ItemsGrid.DataSource = ds;
      ItemsGrid.DataBind();
      Message.Text = "";
    }
    else
    {
      Message.Text = "No records found.";
    }
  }

  DataSet RunQuery(String connectionString, String queryString)
  {
    SqlConnection connection = new SqlConnection(connectionString);
    SqlDataAdapter adapter;
    DataSet ds;

    try
    {
      // Run the query and create the DataSet object.
      ds = new DataSet();
      adapter = new SqlDataAdapter(queryString, connection);
      adapter.Fill(ds);
    }
    catch(Exception ex)
    {
      // Display an error message.
      Message.Text = "Unable to query data source.";
      ds = null;
    }
    finally
    {
      connection.Close();
    }

    return ds;
  }

  void ItemsGrid_ItemCommand(Object sender, DataGridCommandEventArgs
 e)
  {
    // Use the CommandSource property to retrieve the LinkButton
    // control that raised the event.
    LinkButton selectButton = (LinkButton)e.CommandSource;

    // Display the desciption for the job title.
    Message.Text = selectButton.Text + " - ";

    switch (selectButton.Text)
    {
      case "Sales Representative":
        Message.Text += "Sells products to customers.";
        break;
      case "Vice President, Sales":
        Message.Text += "Manages the sales division.";
        break;
      case "Sales Manager":
        Message.Text += "Manages a sales team.";
        break;
      case "Inside Sales Coordinator":
        Message.Text += "Coordinates cross team communications.";
        break;
      default:
        Message.Text += "To be determined.";
        break;
    }
  }
  
</script>

<html>
  <body>
    <form runat="server">

      <h3>DataGridCommandEventArgs CommandSource Example</h3>

      <asp:datagrid
        id="ItemsGrid"
        autogeneratecolumns="false"
        onitemcommand="ItemsGrid_ItemCommand"  
        runat="server">

          <columns>
          
            <asp:BoundColumn DataField="FirstName"
              headertext="First Name"/>
            <asp:BoundColumn DataField="LastName"
              headertext="Last Name"/>
            <asp:buttoncolumn buttontype="LinkButton"
              datatextfield="Title"
              headertext="Title"/> 
          
          </columns>
        
      </asp:datagrid>
      
      <br/><br/>
      
      <asp:label id="Message" 
        runat="server"/>

    </form>
  </body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridCommandEventArgs クラス
DataGridCommandEventArgs メンバ
System.Web.UI.WebControls 名前空間
DataGrid クラス



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

辞書ショートカット

すべての辞書の索引

DataGridCommandEventArgs.CommandSource プロパティのお隣キーワード
検索ランキング

   

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



DataGridCommandEventArgs.CommandSource プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS