I use the gridview control and do the paging and sorting manually. Here is the paging method:
protected void gdvMainList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdvMainList.PageIndex = e.NewPageIndex;
gdvMainList.DataSource = dtConsentReleaseList;
gdvMainList.DataBind();
}
I have a static datatable having an Id column:
dtConsentReleaseList.Columns.Add("Id");
dtConsentReleaseList.Columns.Add("StartDate");
dtConsentReleaseList.Columns.Add("EndDate");
dtConsentReleaseList.Columns.Add("Contact");
I assign datakeynames "Id" in my GridView. And I also have a print button on each line. When I click this button, this code runs:
else if (e.CommandName == "New")
{
int selectedIndex = Convert.ToInt32(e.CommandArgument);
int consentReleaseId = Convert.ToInt32(gdvMainList.DataKeys[selectedIndex].Value);
string openReportScript = Utility.OpenReport(ResolveClientUrl("~/Reports/Consumer/ConsentReleaseReport.aspx?Id=" + consentReleaseId + "&ReportTitle=ConsentForRelease"));
ScriptManager.RegisterClientScriptBlock(upConsentRelease, upConsentRelease.GetType(), "Pop up", openReportScript, true);
}
but when I change the page and press the print button, an exception is raised on this line:
int consentReleaseId = Convert.ToInt32(gdvMainList.DataKeys[selectedIndex].Value);
An exception:
Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
I think I'm doing something wrong in the paging method.
Any help please?
asma source
share