Friday, May 16, 2008

GridView Paging Style



<
asp:GridView runat="server" ID="grdCustomers" cssclass="blackborder"
CellPadding="3"
style="width:800px;"
AutoGenerateColumns="false" onrowcommand="grdCustomers_RowCommand"
PageSize="4" AllowPaging="true" onpageindexchanging="grdCustomers_PageIndexChanging"
PagerSettings-Mode="NumericFirstLast"
PagerSettings-PageButtonCount="10"
>
<AlternatingRowStyle CssClass="gridalternate" />
<HeaderStyle CssClass="gridheader" />
<PagerStyle cssClass="gridpager" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="teal" />
<Columns>
<asp:HyperLinkField DataTextField="Company" HeaderText="Company" DataNavigateUrlFields="Pk"
DataNavigateUrlFormatString="ShowCustomer.aspx?id={0}" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="LastOrder" HeaderText="Last Order" />
<asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="center" ItemStyle-Width="70px" >
<ItemTemplate>
<asp:LinkButton runat="server" CommandName="DeleteCustomer"
CommandArgument='<%# Eval("pk") %>'
Text="Delete" >asp:LinkButton>
ItemTemplate>
asp:TemplateField>
Columns>
asp:GridView>

I use a pager style which is defined something like this in a CSS stylesheet:

.gridpager, .gridpager td
{
text-align: right;
color: cornsilk;
font-weight: bold;
text-decoration: none;
}
.gridpager a
{
color: White;
font-weight: normal;
}