GridView.RowStyle Propiedad

Definición

Obtiene una referencia al objeto TableItemStyle que permite establecer la apariencia de las filas de datos alternas en un control GridView.

public:
 property System::Web::UI::WebControls::TableItemStyle ^ RowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle RowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.RowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property RowStyle As TableItemStyle

Valor de propiedad

TableItemStyle

Referencia a TableItemStyle que representa el estilo de las filas de datos en un control GridView.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo usar la RowStyle propiedad para definir mediante declaración el estilo de las filas de elemento en un GridView control .


<%@ 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>

Comentarios

Utilice la RowStyle propiedad para controlar la apariencia de las filas de datos en un GridView control . Cuando también se establece la AlternatingRowStyle propiedad , las filas de datos se muestran alternando entre la RowStyle configuración y la AlternatingRowStyle configuración. Esta propiedad es de solo lectura; sin embargo, puede establecer las propiedades del TableItemStyle objeto que devuelve. Las propiedades se pueden establecer mediante declaración mediante uno de los métodos siguientes:

  • Coloque un atributo en la etiqueta de apertura del GridView control con el formato Property-Subproperty, donde Subproperty es una propiedad del TableItemStyle objeto (por ejemplo, RowStyle-ForeColor).

  • Anida un <RowStyle> elemento entre las etiquetas de apertura y cierre del GridView control.

Las propiedades también se pueden establecer mediante programación en el formulario Property.Subproperty (por ejemplo, RowStyle.ForeColor). La configuración común suele incluir un color de fondo personalizado, un color de primer plano y propiedades de fuente.

Se aplica a

Consulte también