0

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));
        }
    }
Juventus tech
  • 95
  • 4
  • 13
  • no sorry, it's not a duplicate of another question, it's different – Juventus tech Dec 19 '15 at 12:26
  • It's absolutely not different, if you read the accepted answer, you should have the knowledge to debug and fix your code. Clearly `index` is wrong. – Rob Dec 19 '15 at 12:36

0 Answers0