Fork me on GitHub

AspNetPager demo - Using image buttons

This sample demonstrate how to use image buttons in AspNetPager control.

Order IDOrder DateCompany NameEmployee Name
110745/6/1998Simons bistroRobert King
110755/6/1998Richter SupermarktLaura Callahan
110765/6/1998Bon app'Margaret Peacock
110775/6/1998Rattlesnake Canyon GroceryNancy Davolio
110705/5/1998Lehmanns MarktstandAndrew Fuller
110715/5/1998LILA-SupermercadoNancy Davolio
110725/5/1998Ernst HandelMargaret Peacock
110735/5/1998Pericles Comidas clásicasAndrew Fuller
110675/4/1998Drachenblut DelikatessenNancy Davolio
110685/4/1998Queen CozinhaLaura Callahan
  

ImageButtons.aspx:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" HeaderStyle-BackColor="#CCCCFF" AlternatingRowStyle-BackColor="#eaeaea" RowStyle-BackColor="#FAF3DC" CssClass="table table-bordered">
            <Columns>
                <asp:BoundField DataField="orderid" HeaderText="Order ID" />
                <asp:BoundField DataField="orderdate" HeaderText="Order Date" DataFormatString="{0:d}" />
                <asp:BoundField DataField="companyname" HeaderText="Company Name" />
                <asp:BoundField DataField="employeename" HeaderText="Employee Name" />
            </Columns>
    </asp:GridView>
    <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center"
        pagingbuttontype="Image" width="100%" ImagePath="../images/" ButtonImageNameExtension="n" ButtonImageExtension=".gif" 
        DisabledButtonImageNameExtension="g" CpiButtonImageNameExtension="r" PagingButtonSpacing="10px" ButtonImageAlign="left"
        OnPageChanged="AspNetPager1_PageChanged"></webdiyer:aspnetpager>

ImageButtons.aspx.cs:

using System;
using System.Collections.Generic;
using System.Web.UI;

public partial class ImageButtons_Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AspNetPager1.RecordCount = OrderObjectData.GetOrderCount();
            bindData();
        }
    }

    void bindData()
    {
        List<OrderObject> orders = OrderObjectData.GetPagedOrders(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
        GridView1.DataSource = orders;
        GridView1.DataBind();
    }

    protected void AspNetPager1_PageChanged(object src,EventArgs e)
    {
        bindData();
    }
}