GridView.EmptyDataTemplate 属性

获取或设置在 GridView 控件绑定到不包含任何记录的数据源时所呈现的空数据行的用户定义内容。

 

下面的代码示例演示如何定义在 GridView 控件绑定到不包含任何记录的数据源时所显示的空数据行的自定义模板。

 

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

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

      <asp:gridview id="CustomersGridView"
        datasourceid="CustomersSqlDataSource"
        autogeneratecolumns="true"
        runat="server">
        
        <emptydatarowstyle backcolor="LightBlue"
          forecolor="Red"/>

                    
         <emptydatatemplate>
               
          <asp:image id="NoDataImage"
            imageurl="~/images/Image.jpg"
            runat="server"/>
                       
            No Data Found. 
               
        </emptydatatemplate> 
                
      </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. The following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource" 
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
           
    </form>
  </body>
</html>

 

posted @ 2009-04-17 12:22  minmin8110  阅读(292)  评论(0)    收藏  举报