Hi,
In my website there is a List<string> which I try to print in several pages in DataGrid. The problem is in the paging links (1 2 3 4 ...). The first page of contents is printed properly. But whenever I try to click on the second page of results, there comes an execution error. It appears at
ResGrid.DataBind();
line and it says that CurrentPageIndex should be >=0 and less than PageCount.
Can anyone help me? This is the code i'm talking about
.aspx file
<asp:label id="lblTracker" runat="server" />
<asp:DataGrid
runat="server"
ID="ResGrid"
AllowPaging="true"
cellpadding=5
gridlines="Vertical"
onPageIndexChanged="setPage"
PageSize="15">
<itemstyle HorizontalAlign="Left" VerticalAlign="Top"/>
<pagerstyle
position="Bottom"
Mode="NumericPages"
horizontalalign="right" />
</asp:DataGrid>
aspx.cs file
List<string> Results_final = new List<string>();
bindGrid();
protected void bindGrid()
{
ResGrid.DataSource = Results_final;
ResGrid.DataBind();
lblTracker.Text = "Page " + (ResGrid.CurrentPageIndex + 1) + " of " + ResGrid.PageCount;
}
protected void setPage(Object src, DataGridPageChangedEventArgs e)
{
ResGrid.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}