I use this Reference For Paging In GridView. But Still Have Errors.
Server Error in '/' Application.
The GridView 'gvInvoices' fired event PageIndexChanging which wasn't handled.
Paging in ASP.Net GridView Example
namespace _5M_Solution
{
public partial class Invoices : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.HtmlControls.HtmlGenericControl li = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Page.Master.FindControl("Main_lnkmnu_Harqat_Fawatir");
li.Attributes.Add("class", "menu single-menu active");
if (!this.IsPostBack)
{
this.BindDropDownList();
this.BindData(string.Empty, string.Empty);
}
}
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (ddlBranchNumbers.SelectedIndex == 0)
{
this.BindData(string.Empty, string.Empty);
ddlMachineNumbers.Visible = false;
}
if (ddlBranchNumbers.SelectedIndex > 0)
{
ddlMachineNumbers.Visible = false;
this.BindData(ddlBranchNumbers.SelectedValue, string.Empty);
}
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvInvoices.PageIndex = e.NewPageIndex;
this.BindData(string.Empty, string.Empty);
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Invoices.aspx.cs" Inherits="_5M_Solution.Invoices" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="layout-px-spacing">
<div class="page-header">
</div>
<div class="row layout-top-spacing">
<div class="col-xl-12 col-lg-12 col-md-12 col-12 layout-spacing">
<div class="widget widget-content-area br-4">
<div class="widget-one">
<div class="row mt-3">
<div class="col-12">
<asp:GridView runat="server" CssClass="table table-striped table-bordered"
AutoGenerateColumns="false" AllowPaging="true" PageSize="14"
Width="100%" ID="gvInvoices">
<Columns>
<asp:BoundField DataField="branch_num" HtmlEncode="false" HeaderText="رقم المحطة<br/>Branch No" />
<asp:BoundField DataField="_date" HtmlEncode="false" DataFormatString="{0:dd/MM/yyyy}" HeaderText="التاريخ<br/>Date" />
<asp:BoundField DataField="invoice_number" HtmlEncode="false" HeaderText="رقم الفاتورة<br/>Invoice No" />
<asp:BoundField DataField="item" HtmlEncode="false" HeaderText="الصنف<br/>Gasoline Type" />
<asp:BoundField DataField="machineID" Visible="false" HtmlEncode="false" HeaderText="رقم المكينة<br/>Machine ID" />
<asp:BoundField DataField="payment_type" HtmlEncode="false" HeaderText="طريقة الدفع<br/>Payment Type" />
<asp:BoundField DataField="price" HtmlEncode="false" HeaderText="السعر<br/>Price" />
<asp:BoundField DataField="qty" HtmlEncode="false" HeaderText="الكمية<br/>Qty" />
<asp:BoundField DataField="total" HtmlEncode="false" HeaderText="الإجمالي<br/>Total Amount" />
<asp:BoundField DataField="vat_amount" HtmlEncode="false" HeaderText="الضريبة<br/>VAT Amount" />
<asp:BoundField DataField="userID" HtmlEncode="false" HeaderText="المستخدم<br/>User" />
<asp:BoundField DataField="buyer_nameAR" HtmlEncode="false" HeaderText="اسم العميل<br/>Customer Name" />
<asp:BoundField DataField="coupon" HtmlEncode="false" HeaderText="رقم الكوبون<br/>Coupon No" />
</Columns>
<PagerStyle HorizontalAlign="Center" CssClass="GridPager" />
<HeaderStyle HorizontalAlign="Center" />
</asp:GridView>
</div>
</div>
<div class="row">
<div class="col-md-12 text-right">
<asp:Label ID="lblTotal" Text="إجمالي عدد السجلات" runat="server" />
<asp:Label ID="lblTotalRecords" CssClass="badge-chip badge-danger mt-1 mb-1 ml-1" runat="server" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content>