GridView.EmptyDataRowStyle Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan referensi ke TableItemStyle objek yang memungkinkan Anda mengatur tampilan baris data kosong yang dirender saat GridView kontrol terikat ke sumber data yang tidak berisi rekaman apa pun.
public:
property System::Web::UI::WebControls::TableItemStyle ^ EmptyDataRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle EmptyDataRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.EmptyDataRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property EmptyDataRowStyle As TableItemStyle
Nilai Properti
Referensi ke TableItemStyle yang memungkinkan Anda mengatur tampilan baris null.
- Atribut
Contoh
Contoh berikut menunjukkan cara mengatur EmptyDataRowStyle properti secara deklaratif untuk menentukan latar belakang biru muda dan font merah untuk baris 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>GridView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" 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"
alternatetext="No Image"
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>
<%@ 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>GridView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" 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"
alternatetext="No Image"
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>
Keterangan
EmptyDataRowStyle Gunakan properti untuk mengontrol tampilan baris null dalam GridView kontrol. Baris null ditampilkan ketika sumber data yang terikat ke kontrol tidak berisi rekaman apa pun. Properti ini bersifat baca-saja; namun, Anda dapat mengatur properti objek yang TableItemStyle dikembalikannya. Properti dapat diatur secara deklaratif menggunakan salah satu metode berikut:
Tempatkan atribut dalam tag GridView pembuka kontrol dalam formulir
Property-Subproperty, di manaSubpropertyadalah properti TableItemStyle objek (misalnya,EmptyDataRowStyle-ForeColor).Sarangkan
<EmptyDataRowStyle>elemen antara tag GridView pembuka dan penutup kontrol.
Properti juga dapat diatur secara terprogram dalam formulir Property.Subproperty (misalnya, EmptyDataRowStyle.ForeColor). Pengaturan umum biasanya mencakup warna latar belakang kustom, warna latar depan, dan properti font.