GridView.AlternatingRowStyle 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 alternatif dalam GridView kontrol.
public:
property System::Web::UI::WebControls::TableItemStyle ^ AlternatingRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle AlternatingRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.AlternatingRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property AlternatingRowStyle As TableItemStyle
Nilai Properti
Referensi ke TableItemStyle yang mewakili gaya baris data alternatif dalam GridView kontrol.
- Atribut
Contoh
Contoh berikut menunjukkan cara menggunakan AlternatingRowStyle properti untuk secara deklaratif menentukan gaya untuk baris data alternatif dalam GridView kontrol.
<%@ 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 RowStyle and AlternatingRowStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView RowStyle and AlternatingRowStyle Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
runat="server">
<rowstyle backcolor="LightCyan"
forecolor="DarkBlue"
font-italic="true"/>
<alternatingrowstyle backcolor="PaleTurquoise"
forecolor="DarkBlue"
font-italic="true"/>
</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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
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>GridView RowStyle and AlternatingRowStyle Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView RowStyle and AlternatingRowStyle Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSource"
autogeneratecolumns="true"
emptydatatext="No data available."
runat="server">
<rowstyle backcolor="LightCyan"
forecolor="DarkBlue"
font-italic="true"/>
<alternatingrowstyle backcolor="PaleTurquoise"
forecolor="DarkBlue"
font-italic="true"/>
</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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
Keterangan
AlternatingRowStyle Gunakan properti untuk mengontrol tampilan baris data alternatif dalam GridView kontrol. Ketika properti ini diatur, baris data ditampilkan bergantian antara RowStyle pengaturan dan AlternatingRowStyle pengaturan. 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,AlternatingRowStyle-ForeColor).Sarangkan
<AlternatingRowStyle>elemen antara tag GridView pembuka dan penutup kontrol.
Properti juga dapat diatur secara terprogram dalam formulir Property.Subproperty (misalnya, AlternatingRowStyle.ForeColor). Pengaturan umum biasanya mencakup warna latar belakang kustom, warna latar depan, dan properti font.