Pages

Showing posts with label Page. Show all posts
Showing posts with label Page. Show all posts

Tuesday, June 4, 2013

Creating ASPNET WebForm GridView Paging

Here is code for Creating ASPNET WebForm GridView Paging :

On *.aspx files, gridview need : properties AllowPaging and events OnPageIndexChanging
You can set and configure the pager style & setting by changing the PagerStyle and PagerSettings.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True"  OnPageIndexChanging="GridView1_PageIndexChanging>
        <PagerStyle HorizontalAlign="Center" CssClass="foo" />
        <PagerSettings Mode="NumericFirstLast" PageButtonCount="5" FirstPageText="First" LastPageText="Last" />
</asp:GridView>

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
        GridView1.PageIndex = e.NewPageIndex;
        LoadData();
}

private void LoadData()
{
        GridView1.DataSource = mylist.ToList();
        GridView1.DataBind();
}

LoadData is a function to bind list or array to GridView. 
We can Manage the list by put them in a ViewState or in a Session to Keep Consistent List.
This could happend when you have searched list or sorted it.

ShareThis