GridView - ordernar pelo cabeçalho

<< Click to Display Table of Contents >>

Navigation:  ASP.NET > ASP Controls >

GridView - ordernar pelo cabeçalho

Previous pageReturn to chapter overviewNext page

Default.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!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 id="Head1" runat="server">

  <title></title>

</head>

<body>

  <form id="form1" runat="server">

  <div>

   

      <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"

          AllowPaging="True" AllowSorting="True" BackColor="LightGoldenrodYellow"

          BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"

          GridLines="None" AutoGenerateColumns="False">

          <AlternatingRowStyle BackColor="PaleGoldenrod" />

          <Columns>

              <asp:CommandField ShowSelectButton="True" />

              <asp:BoundField DataField="id" HeaderText="Código" SortExpression="id"/>

              <asp:BoundField DataField="nome" HeaderText="Nome" SortExpression="nome"/>

              <asp:BoundField DataField="status" HeaderText="Status" SortExpression="status"/>

              <asp:BoundField DataField="data" DataFormatString="{0:d}" HeaderText="Data" SortExpression="data"/>

              <asp:BoundField DataField="salario" HeaderText="Salário" SortExpression="salario"/>

          </Columns>

          <FooterStyle BackColor="Tan" />

          <HeaderStyle BackColor="Tan" Font-Bold="True" />

          <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"

              HorizontalAlign="Center" />

          <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />

          <SortedAscendingCellStyle BackColor="#FAFAE7" />

          <SortedAscendingHeaderStyle BackColor="#DAC09E" />

          <SortedDescendingCellStyle BackColor="#E1DB9C" />

          <SortedDescendingHeaderStyle BackColor="#C2A47B" />

      </asp:GridView>

      <asp:SqlDataSource ID="SqlDataSource1" runat="server"

          ConnectionString="<%$ ConnectionStrings:testeConnectionString %>"

          ProviderName="<%$ ConnectionStrings:testeConnectionString.ProviderName %>"

          SelectCommand="SELECT id, nome, data, status, salario FROM tabela">

      </asp:SqlDataSource>

   

  </div>

  </form>

</body>

</html>

 

Default.aspx.cs

 

nada

 

web.config

 

<configuration>

 <connectionStrings>

   <add name="testeConnectionString" connectionString="server=localhost;User Id=root;password=123456;database=teste" providerName="MySql.Data.MySqlClient"/>

 </connectionStrings>

 <system.web>

   <compilation debug="true" targetFramework="4.0"/>

 </system.web>

</configuration>