通过通过分别配置 PagerStyle 和 PagerSettings 属性,自定义页导航的样式和设置
关键代码段:
<PagerSettings Mode="NextPreviousFirstLast" Position="TopAndBottom" FirstPageImageUrl="~/Images/First.gif"
LastPageImageUrl="~/Images/Last.gif" NextPageImageUrl="~/Images/Next.gif" PreviousPageImageUrl="~/Images/Prev.gif" />
<PagerStyle ForeColor="White" HorizontalAlign="Right" BackColor="#284775" />
全部代码:
<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
<title>Sorting Data Using GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" AllowSorting="true" Allowpaging="true" runat="server" DataSourceID="SqlDataSource1"
AutoGenerateColumns="False">
<PagerSettings Mode="NextPreviousFirstLast" Position="TopAndBottom" FirstPageImageUrl="~/Images/First.gif"
LastPageImageUrl="~/Images/Last.gif" NextPageImageUrl="~/Images/Next.gif" PreviousPageImageUrl="~/Images/Prev.gif" />
<PagerStyle ForeColor="White" HorizontalAlign="Right" BackColor="#284775" />
<Columns>
<asp:BoundField HeaderText="ID" DataField="au_id" SortExpression="au_id" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname" SortExpression="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname" SortExpression="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone" SortExpression="phone" />
<asp:BoundField HeaderText="Address" DataField="address" SortExpression="address" />
<asp:BoundField HeaderText="City" DataField="city" SortExpression="city" />
<asp:BoundField HeaderText="State" DataField="state" SortExpression="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip" SortExpression="zip" />
<asp:CheckBoxField HeaderText="Contract" SortExpression="contract" DataField="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address], [city], [state], [zip], [contract] FROM [authors]"
ConnectionString="<%$ ConnectionStrings:Pubs %>" />
</form>
</body>
</html>
Web.config代码:
?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Pubs" connectionString="Server=localhost;uid=sa;pwd=123456; database=pubs;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true"/>
<caching>
<sqlCacheDependency enabled="true" pollTime="1000">
<databases>
<add name="Pubs" connectionStringName="Pubs"/>
</databases>
</sqlCacheDependency>
</caching>
</system.web>
</configuration>
结果:
|
||||||||||
ID | Last Name | First Name | Phone | Address | City | State | Zip Code | Contract | ||
---|---|---|---|---|---|---|---|---|---|---|
172-32-1176 | White | Johnson | 408 496-7223 | 10932 Bigge Rd. | Menlo Park | CA | 94025 | |||
213-46-8915 | Green | Marjorie | 415 986-7020 | 309 63rd St. #411 | Oakland | CA | 94618 | |||
238-95-7766 | Carson | Cheryl | 415 548-7723 | 589 Darwin Ln. | Berkeley | CA | 94705 | |||
267-41-2394 | O'Leary | Michael | 408 286-2428 | 22 Cleveland Av. #14 | San Jose | CA | 95128 | |||
274-80-9391 | Straight | Dean | 415 834-2919 | 5420 College Av. | Oakland | CA | 94609 | |||
341-22-1782 | Smith | Meander | 913 843-0462 | 10 Mississippi Dr. | Lawrence | KS | 66044 | |||
409-56-7008 | Bennet | Abraham | 415 658-9932 | 6223 Bateman St. | Berkeley | CA | 94705 | |||
427-17-2319 | Dull | Ann | 415 836-7128 | 3410 Blonde St. | Palo Alto | CA | 94301 | |||
472-27-2349 | Gringlesby | Burt | 707 938-6445 | PO Box 792 | Covelo | CA | 95428 | |||
486-29-1786 | Locksley | Charlene | 415 585-4620 | 18 Broadway Av. | San Francisco | CA | 94130 | |||
|