GridViewSortEventHandler デリゲートとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > GridViewSortEventHandler デリゲートの意味・解説 

GridViewSortEventHandler デリゲート

メモ : このデリゲートは、.NET Framework version 2.0新しく追加されたものです。

GridView コントロールSorting イベント処理するメソッド表します

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

Public Delegate Sub GridViewSortEventHandler
 ( _
    sender As Object, _
    e As GridViewSortEventArgs _
)
Dim instance As New GridViewSortEventHandler(AddressOf
 HandlerMethod)
public delegate void GridViewSortEventHandler
 (
    Object sender,
    GridViewSortEventArgs e
)
public delegate void GridViewSortEventHandler
 (
    Object^ sender, 
    GridViewSortEventArgs^ e
)
/** @delegate */
public delegate void GridViewSortEventHandler
 (
    Object sender, 
    GridViewSortEventArgs e
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントソース

e

イベント データ格納している GridViewSortEventArgs オブジェクト

解説解説
使用例使用例

GridViewSortEventHandler デリゲートを、プログラムによって GridView コントロールSorting イベント追加する方法次の例に示します

<%@ Page language="VB" %>

<script runat="server">

    Sub Page_Load(ByVal sender As
 Object, ByVal e As EventArgs)
        
        ' Create a new GridView object.
        Dim authorGridView As GridView = New
 GridView
         
        ' Set the GridView object's properties.
        authorGridView.ID = "AuthorGridView"
        authorGridView.DataSourceID = "AuthorsSqlDataSource"
        authorGridView.AutoGenerateColumns = True
        authorGridView.AllowSorting = True
        
        ' Programmatically register the event-handling methods.
        AddHandler authorGridView.Sorting, AddressOf
 AuthorsGridView_Sorting
        
        ' Add the GridView object to the Controls collection
        ' of the PlaceHolder control.
        GridViewPlaceHolder.Controls.Add(authorGridView)
        
    End Sub
    
    Sub AuthorsGridView_Sorting(ByVal sender
 As Object, ByVal e As
 GridViewSortEventArgs)
    
        ' Cancel the sorting operation if the user attempts to sort
        ' the Contract column.
        If e.SortExpression = "contract"
 Then

            e.Cancel = True
            Message.Text = "You cannot sort the Contract column."
        
        Else
      
            ' Clear the message label.
            Message.Text = ""
        
        End If
    
    End Sub

</script>

<html>
    <body>
        <form runat="server">
        
            <h3>GridViewSortEventHandler Example</h3>
            
            <asp:label id="Message"
                forecolor="Red"
                runat="server"/>
                
            <br/>
            
            <asp:placeholder id="GridViewPlaceHolder"
                runat="Server"/>
            
            <!-- This example uses Microsoft SQL Server and
 connects -->
            <!-- to the Pubs sample database.             
            -->
            <asp:sqldatasource id="AuthorsSqlDataSource"
  
                selectcommand="SELECT [au_id], [au_lname], [au_fname],
 [address], [city], [state], [zip], [contract] FROM [authors]"
                updatecommand="UPDATE authors SET au_lname=@au_lname,
 au_fname=@au_fname, address=@address, city=@city, state=@state, zip=@zip, contract=@contract
 WHERE (authors.au_id = @au_id)"
                connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
                runat="server">
            </asp:sqldatasource>
            
        </form>
    </body>
</html>

<%@ Page language="C#" %>

<script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {
        
        // Create a new GridView object.
        GridView authorGridView = new GridView();
         
        // Set the GridView object's properties.
        authorGridView.ID = "AuthorGridView";
        authorGridView.DataSourceID = "AuthorsSqlDataSource"; 
        authorGridView.AutoGenerateColumns = true;
        authorGridView.AllowSorting = true;
        
        // Programmatically register the event-handling methods.
        authorGridView.Sorting += new GridViewSortEventHandler(this.AuthorsGridView_Sorting);
        
        // Add the GridView object to the Controls collection
        // of the PlaceHolder control.
        GridViewPlaceHolder.Controls.Add(authorGridView);
        
    }
    
    void AuthorsGridView_Sorting(Object sender, GridViewSortEventArgs
 e)
    {
    
        // Cancel the sorting operation if the user attempts to sort
        // the Contract column.
        if(e.SortExpression == "contract")
        {
            e.Cancel = true;
            Message.Text = "You cannot sort the Contract column.";
        }
        else
        {
            // Clear the message label.
            Message.Text = "";
        }
    
    }

</script>

<html>
    <body>
        <form runat="server">
        
            <h3>GridViewSortEventHandler Example</h3>
            
            <asp:label id="Message"
                forecolor="Red"
                runat="server"/>
                
            <br/>
            
            <asp:placeholder id="GridViewPlaceHolder"
                runat="Server"/>
            
            <!-- This example uses Microsoft SQL Server and connects -->
            <!-- to the Pubs sample database.                         -->
            <asp:sqldatasource id="AuthorsSqlDataSource"  
                selectcommand="SELECT [au_id], [au_lname], [au_fname], [address],
 [city], [state], [zip], [contract] FROM [authors]"
                updatecommand="UPDATE authors SET au_lname=@au_lname, au_fname=@au_fname,
 address=@address, city=@city, state=@state, zip=@zip, contract=@contract WHERE
 (authors.au_id = @au_id)"
                connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
                runat="server">
            </asp:sqldatasource>
            
        </form>
    </body>
</html>

GridViewSortEventHandler デリゲートを、宣言によって GridView コントロールSorting イベント追加する方法次の例に示します

<%@ Page language="VB" %>

<script runat="server">
  
  Sub CustomersGridView_Sorting(sender As Object,
 e As GridViewSortEventArgs)
  
    ' Cancel the sorting operation if the user attempts
    ' to sort by address.
    If e.SortExpression = "Address"
 Then
    
      e.Cancel = True
      Message.Text = "You cannot sort by address."
      SortInformationLabel.Text = ""
    
    Else
    
      Message.Text = ""
      
    End If
    
  End Sub

  Sub CustomersGridView_Sorted(ByVal sender
 As Object, ByVal e As
 EventArgs)
 
    ' Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " &
 _
      CustomersGridView.SortExpression.ToString() & _
      " in " & CustomersGridView.SortDirection.ToString()
 & _
      " order."
    
  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView Sorted and Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
        
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<script runat="server">
  
  void CustomersGridView_Sorting(Object sender, GridViewSortEventArgs
 e)
  {
    // Cancel the sorting operation if the user attempts
    // to sort by address.
    if (e.SortExpression == "Address")
    {
      e.Cancel = true;
      Message.Text = "You cannot sort by address.";
      SortInformationLabel.Text = "";
    }
    else
    {
      Message.Text = "";
    }
  }

  void CustomersGridView_Sorted(Object sender, EventArgs e)
  {
    // Display the sort expression and sort direction.
    SortInformationLabel.Text = "Sorting by " +
      CustomersGridView.SortExpression.ToString() +
      " in " + CustomersGridView.SortDirection.ToString()
 +
      " order.";
  }
  
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView Sorting Example</h3>

      <asp:label id="Message"
        forecolor="Red"
        runat="server"/>
        
      <br/>
        
      <asp:label id="SortInformationLabel"
        forecolor="Navy"
        runat="server"/>
                
      <br/>  

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        emptydatatext="No data available." 
        allowsorting="true"
        onsorting="CustomersGridView_Sorting"
        onsorted="CustomersGridView_Sorted"  
        runat="server">
                
      </asp:gridview>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
        
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewSortEventArgs クラス
GridView.Sorting イベント
OnSorting
その他の技術情報
イベントデリゲート



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

辞書ショートカット

すべての辞書の索引

GridViewSortEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



GridViewSortEventHandler デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS