DetailsView.EmptyDataText 属性

定义

获取或设置在 DetailsView 控件绑定到不包含任何记录的数据源时所呈现的空数据行中显示的文本。Gets or sets the text to display in the empty data row rendered when a DetailsView control is bound to a data source that does not contain any records.

public:
 virtual property System::String ^ EmptyDataText { System::String ^ get(); void set(System::String ^ value); };
public virtual string EmptyDataText { get; set; }
member this.EmptyDataText : string with get, set
Public Overridable Property EmptyDataText As String

属性值

要在空数据行中显示的文本。The text to display in the empty data row. 默认值为空字符串 (""),表示尚未设置此属性。The default is an empty string (""), which indicates that this property is not set.

示例

下面的代码示例演示如何使用EmptyDataText属性指定要在空数据行中显示的文本。The following code example demonstrates how to use the EmptyDataText property to specify the text to display in the empty data row.


<%@ 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>DetailsView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataText Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/> 
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        
        <!-- The select query of the following SqlDataSource     -->
        <!-- control has been intentionally set to return no     --> 
        <!-- results to demonstrate the empty data row.          -->      
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE [state]='FL'"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
          runat="server">
        </asp:sqldatasource>
            
      </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>DetailsView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataText Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/> 
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        
        <!-- The select query of the following SqlDataSource     -->
        <!-- control has been intentionally set to return no     --> 
        <!-- results to demonstrate the empty data row.          -->      
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE [state]='FL'"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
          runat="server">
        </asp:sqldatasource>
            
      </form>
  </body>
</html>

注解

当绑定到控件的数据源不DetailsView包含任何记录时, 将在控件中显示空数据行。The empty data row is displayed in a DetailsView control when the data source that is bound to the control does not contain any records. EmptyDataText使用属性指定要在空数据行中显示的文本。Use the EmptyDataText property to specify the text to display in the empty data row. 若要控制空数据行的样式, 请使用EmptyDataRowStyle属性。To control the style of the empty data row, use the EmptyDataRowStyle property. 或者, 您可以通过设置EmptyDataTemplate属性而不是此属性, 为空数据行定义自己的自定义用户界面 (UI)。Alternatively, you can define your own custom user interface (UI) for the empty data row by setting the EmptyDataTemplate property instead of this property.

备注

如果同时设置EmptyDataTextEmptyDataTemplate和属性, 则EmptyDataTemplate属性优先。If both the EmptyDataText and EmptyDataTemplate properties are set, the EmptyDataTemplate property takes precedence.

的值EmptyDataText存储在视图状态中。The value of EmptyDataText is stored in view state.

设置此属性后, 可以使用设计器工具自动将此属性的值保存到资源文件中。The value of this property, when set, can be saved automatically to a resource file by using a designer tool. 有关详细信息, 请LocalizableAttribute参阅和全球化和本地化For more information, see LocalizableAttribute and Globalization and Localization.

适用于

另请参阅