ASP.NET Datagrid features an excellent capability termed as data paging support. After paging is enabled in DataGrid, you can view a fixed number of records that is featured at a time. You can also view the paging UI at the bottom of the DataGrid. This is required for navigating through the DataGrid. To move ‘Forward’ and ‘Backward’, paging UI is required. Better paging codes can be written if stored procedures are used.

The following codes can be used for paging of data grid:

    <asp:datagrid id="grdClaim" runat="server" Width="100%" ForeColor="White"               AllowSorting="True"
AutoGenerateColumns="False" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3"
GridLines="Horizontal" PageSize="50" AllowPaging="True" ShowFooter="True">
<Columns>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="White" CssClass="TableHeader" Mode="NumericPages"></PagerStyle>
</asp:datagrid>

private void grdClaim_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
ViewState["PageIndexToMigrateTo"]=e.NewPageIndex.ToString();
grdClaim.CurrentPageIndex = e.NewPageIndex;
LoadData();
BindData();   
}
                    

Copyright © 2008 VisualBuilder. All rights reserved