Я использую элемент управления gridview и выполняю пейджинг и сортировку вручную.Вот метод Пейджинга:
protected void gdvMainList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdvMainList.PageIndex = e.NewPageIndex;
gdvMainList.DataSource = dtConsentReleaseList;
gdvMainList.DataBind();
}
У меня есть статическая таблица данных с идентификатором столбца:
dtConsentReleaseList.Columns.Add("Id");
dtConsentReleaseList.Columns.Add("StartDate");
dtConsentReleaseList.Columns.Add("EndDate");
dtConsentReleaseList.Columns.Add("Contact");
Я назначаю datakeynames "Id" в моем GridView.И у меня также есть кнопка печати в каждом ряду.Когда я нажимаю эту кнопку, этот код выполняется:
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);
}
, но когда я меняю страницу и нажимаю кнопку печати, в этой строке возникает исключение:
int consentReleaseId = Convert.ToInt32(gdvMainList.DataKeys[selectedIndex].Value);
Исключение составляет:
Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index
Полагаю, я что-то не так делаю в методе подкачки.
Любая помощь, пожалуйста?