GridView.FooterRow 属性在脚注中显示排序方向

属性值

一个 GridViewRow,表示 GridView 控件中的脚注行。

使用 FooterRow 属性以编程方式访问表示 GridView 控件中的脚注行的 GridViewRow 对象。

Note注意

FooterRow 属性仅当 GridView 控件在 RowCreated 事件中创建了脚注行之后才可用。

此属性通常在需要以编程方式操作脚注行时(如添加自定义内容时)使用。对 FooterRow 属性的任何修改必须在呈现 GridView 控件后执行;否则,GridView 控件将会改写所有更改。

下面的代码示例演示如何使用 FooterRow 属性显示脚注行中的排序方向。

 

 

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

<script runat="server">
 
  void CustomersGridView_DataBound(Object sender, EventArgs e)
  {
   
    // Get the header row.
    GridViewRow headerRow = CustomersGridView.HeaderRow;  
   
    // Get the footer row.
    GridViewRow footerRow = CustomersGridView.FooterRow;

    // Set the font color of the header and footer rows
    // based on the sort direction.
    switch (CustomersGridView.SortDirection)
    {
      case SortDirection.Ascending:
        headerRow.ForeColor = System.Drawing.Color.Green;
        footerRow.ForeColor = System.Drawing.Color.Green;
        break;
      case SortDirection.Descending:
        headerRow.ForeColor = System.Drawing.Color.Red;
        footerRow.ForeColor = System.Drawing.Color.Red;
        break;
      default:
        headerRow.ForeColor = System.Drawing.Color.Black;
        footerRow.ForeColor = System.Drawing.Color.Black;
        break;
    }

    // Display the sort order in the footer row.
    footerRow.Cells[0].Text = "Sort Order = " + CustomersGridView.SortDirection.ToString();
     
  }
   
</script>

<html>
  <body>
    <form runat="server">
       
      <h3>GridView HeaderRow and FooterRow Example</h3>

      <asp:gridview id="CustomersGridView"
        datasourceid="CustomersSource"
        autogeneratecolumns="true"
        emptydatatext="No data available."
        allowsorting="true"
        allowpaging="true"
        showheader="true"
        showfooter="true"
        ondatabound="CustomersGridView_DataBound"   
        runat="server">
       
        <headerstyle backcolor="LightCyan"
          forecolor="MediumBlue"/>
                   
        <footerstyle backcolor="LightCyan"
          forecolor="MediumBlue"/>
                       
      </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>

 

posted @ 2009-04-17 13:09  minmin8110  阅读(455)  评论(0)    收藏  举报