ImageField.NullDisplayText Свойство

Определение

Получает или задает текст для отображения в объекте ImageField, когда значение поля, указанного свойством DataImageUrlField равно null.

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

Значение свойства

Текст для отображения, в случаях когда значения поля равно null. По умолчанию используется пустая строка (""), указывающая, что это свойство не задано.

Примеры

В следующем примере показано, как использовать NullDisplayText свойство , чтобы указать текст, отображаемый, если значение поля, указанное свойством DataImageUrlField , равно null.


<%@ 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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </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="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

Комментарии

Если значение поля, указанное свойством DataImageUrlField , равно null, изображение не может отображаться в объекте ImageField . Используйте свойство , NullDisplayText чтобы указать текст, отображаемый на месте изображения. Текст обычно указывает, что обычное изображение недоступно или не может быть найдено.

Примечание

В качестве альтернативы можно отобразить альтернативное изображение, если значение поля равно null , задав NullImageUrl свойство вместо этого свойства. NullImageUrl Если свойства и NullDisplayText заданы, NullImageUrl свойство имеет приоритет.

Значение этого свойства можно автоматически сохранить в файле ресурсов с помощью средства конструктора. Дополнительные сведения см. в разделах LocalizableAttributeи Глобализация и локализация.

Применяется к

См. также раздел