I am facng pagination problem
I have put Pgaesize of 5 in gridview. Gridview is filled with 6 records.First 5 records are shown on 1st page and 6th record on 2nd page.
Now i have put a button in gridview which calls rowcommand upon clicking. Upon clicking when it hits row command then it works fine for the first 5 records but if i click records on 2nd page then it throws Index Out of range exception.
Pagination:
protected void grdViewCases_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdViewCases.PageIndex = e.NewPageIndex;
ShowCases(txtBoxCaseNo.Text);
}
Throws error here at 2nd line i.e. CaseID
protected void grdViewCases_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
short index = Convert.ToInt16(e.CommandArgument);
int CaseID = Convert.ToInt32(grdViewCases.DataKeys[index].Value);
short UserID = Convert.ToInt16(Session["UserID"]);
if (e.CommandName == "cmdSelect")
{
HdnFieldCaseID.Value = Convert.ToString(CaseID);
txtBoxCaseNo.Text = grdViewCases.Rows[index].Cells[1].Text;
grdViewCases.Visible = false;
}
}
catch (Exception ex)
{
Response.Write(Convert.ToString(ex.Message));
}
}