Gladiator
Gladiator

Reputation: 51

Applying Page Indexing or Pagination to GridView

I have a ICollection class LabCollection with an array list. This array list contains another class LabEntity. LabEntity has properties LabID, LabName etc.

I am binding ICollection class to gridview:

LabCollection objLabCollection = new LabCollection();
gridview.DataSource = objlabCollection;
gridview.DataBind();

I want to apply page indexing / pagination to gridview, how can I do that using the above.

Upvotes: 0

Views: 11801

Answers (1)

Software Engineer
Software Engineer

Reputation: 3956

Set AllowPaging=True with PageSize=x in gridview markup, replace x with any number like 10.

Markup:

<asp:GridView ID="gridview" AllowPaging="true" PageSize="10" OnPageIndexChanging="gridview_PageIndexChanging" runat="server" /> 

Code-behind:

protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e){
    FillGrid();
    gridview.PageIndex = e.NewPageIndex;
    gridview.DataBind();
}

Upvotes: 1

Related Questions