Sunday, March 8, 2009

Paging in grid view using asp.net with c#?

There are certain scenario when we required pagination in gridview

Solution for this is very simple.

In .aspx page

<asp:GridView ID="GvEmployee" runat="server" AllowPaging="True" Width="100%" PageSize="10" OnPageIndexChanging="GvEmployee_PageIndexChanging">
<columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>

</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>

In c# Page
protected void GvEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
GvEmployee.PageIndex = e.NewPageIndex;
databind();
}
catch (Exception ex)
{

}
}

1 comment: