Fork me on GitHub

AspNetPager demo - Using Image submit button

This sample demonstrates how to set submit button as image when page index box is displayed.

Order IDOrder DateCompany NameEmployee Name
110294/16/1998Chop-suey ChineseMargaret Peacock
110244/15/1998Eastern ConnectionMargaret Peacock
110254/15/1998Wartian HerkkuMichael Suyama
110264/15/1998Franchi S.p.A.Margaret Peacock
110204/14/1998Ottilies K?seladenAndrew Fuller
110214/14/1998QUICK-StopJanet Leverling
110224/14/1998Hanari CarnesAnne Dodsworth
110234/14/1998B's BeveragesNancy Davolio
110174/13/1998Ernst HandelAnne Dodsworth
110184/13/1998Lonesome Pine RestaurantMargaret Peacock
Total Pages:32 Total Records:318<<<12345678910...>>>  

SubmitButtonImage.aspx:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" 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" PagingButtonSpacing="8px" onpagechanged="AspNetPager1_PageChanged"
         ShowPageIndexBox="Always" SubmitButtonImageUrl="../images/go.jpg" ShowCustomInfoSection="Left" CustomInfoHTML="Total Pages:%PageCount% Total Records:%RecordCount%"
         SubmitButtonStyle="width:32px;height:22px;vertical-align:bottom" CustomInfoTextAlign="Left" urlpaging="True" width="100%" LayoutType="Table" ShowNavigationToolTip="true" UrlPageIndexName="pageindex"></webdiyer:aspnetpager>
        

SubmitButtonImage.aspx.cs:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class SubmitButtonImage_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //cache the number of total records to improve performance
            object obj = Cache[GetType() + "totalOrders"];
            if (obj == null)
            {
                int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
                Cache[GetType() + "totalOrders"] = totalOrders;
                AspNetPager1.RecordCount = totalOrders;
            }
            else
            {
                AspNetPager1.RecordCount = (int)obj;
            }
        }
    }


    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        GridView1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
            new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
            new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
        GridView1.DataBind();
    }
}