GridView.EnableSortingAndPagingCallbacks 屬性

定義

取得或設定值,指出用戶端回呼是否用於排序和分頁作業。

public:
 virtual property bool EnableSortingAndPagingCallbacks { bool get(); void set(bool value); };
public virtual bool EnableSortingAndPagingCallbacks { get; set; }
member this.EnableSortingAndPagingCallbacks : bool with get, set
Public Overridable Property EnableSortingAndPagingCallbacks As Boolean

屬性值

Boolean

true 表示將用戶端回呼用於排序和分頁作業,否則為 false。 預設為 false

例外狀況

Columns 集合包含不支援回呼的資料行,例如 TemplateField

範例

下列範例示範如何使用 EnableSortingAndPagingCallbacks 屬性來啟用用戶端回呼來排序和分頁作業。


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView EnableSortingAndPagingCallbacks Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EnableSortingAndPagingCallbacks Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        allowsorting="true"
        enablesortingandpagingcallbacks="true"        
        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="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView EnableSortingAndPagingCallbacks Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EnableSortingAndPagingCallbacks Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSource" 
        autogeneratecolumns="true"
        emptydatatext="No data available." 
        allowpaging="true"
        allowsorting="true"
        enablesortingandpagingcallbacks="true"        
        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>

備註

根據預設,當執行排序或分頁作業時, GridView 控制項會回傳至伺服器以執行作業。 EnableSortingAndPagingCallbacks當 屬性設定為 true 時,會在用戶端上呼叫服務來執行排序和分頁作業,這樣就不需要回傳至伺服器。

注意

並非所有瀏覽器都支援此功能。 若要判斷瀏覽器是否支援此功能,請使用 SupportsCallback 屬性。

集合中的所有資料行 Columns 都必須支援回呼,此功能才能運作。 Columns如果集合包含不支援回呼的資料行,例如 TemplateField ,就會 NotSupportedException 引發例外狀況。

適用於

另請參閱