Bagikan melalui


FormView.EmptyDataTemplate Properti

Definisi

Mendapatkan atau mengatur konten yang ditentukan pengguna untuk baris data kosong yang FormView dirender saat kontrol terikat ke sumber data yang tidak berisi rekaman apa pun.

public:
 virtual property System::Web::UI::ITemplate ^ EmptyDataTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.FormView))]
public virtual System.Web.UI.ITemplate EmptyDataTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.FormView))>]
member this.EmptyDataTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyDataTemplate As ITemplate

Nilai Properti

ITemplate yang berisi konten kustom untuk baris data kosong. Nilai defaultnya adalah null, yang menunjukkan bahwa properti ini tidak diatur.

Atribut

Contoh

Contoh berikut menunjukkan cara menentukan templat kustom untuk baris data kosong yang FormView ditampilkan saat kontrol terikat ke sumber data yang tidak berisi rekaman apa pun.


<%@ 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>FormView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <emptydatatemplate>
          <table>
            <tr>
              <td>
                <asp:image id="NoDataImage"
                  imageurl="~/Images/NoDataImage.jpg" 
                  alternatetext="No image" 
                  runat="server"/>
              </td>
              <td>
                No records available.
              </td>
            </tr>
          </table>
        </emptydatatemplate>
          
        <pagersettings position="Bottom"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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 select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data row.                   --> 
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees] Where [EmployeeID]=1000"
        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>FormView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <emptydatatemplate>
          <table>
            <tr>
              <td>
                <asp:image id="NoDataImage"
                  imageurl="~/Images/NoDataImage.jpg" 
                  alternatetext="No image" 
                  runat="server"/>
              </td>
              <td>
                No records available.
              </td>
            </tr>
          </table>
        </emptydatatemplate>
          
        <pagersettings position="Bottom"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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 select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data row.                   --> 
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees] Where [EmployeeID]=1000"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

Keterangan

Baris data kosong ditampilkan dalam FormView kontrol saat sumber data yang terikat ke kontrol tidak berisi rekaman apa pun. Anda dapat menentukan antarmuka pengguna kustom (UI) Anda sendiri untuk baris data kosong dengan menggunakan EmptyDataTemplate properti . Untuk menentukan templat kustom untuk baris data kosong, pertama-tama tempatkan <EmptyDataTemplate> tag antara tag FormView pembuka dan penutup kontrol. Anda kemudian dapat mencantumkan konten templat antara tag pembuka dan penutup <EmptyDataTemplate> . Untuk mengontrol gaya baris data kosong, gunakan EmptyDataRowStyle properti . Atau, Anda dapat menggunakan UI bawaan untuk baris data kosong dengan mengatur EmptyDataText properti alih-alih properti ini.

Catatan

EmptyDataText Jika properti dan EmptyDataTemplate diatur, EmptyDataTemplate properti lebih diutamakan.

Berlaku untuk

Lihat juga