Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello everyone, i am facing a problem in my gridview when i go to 1 to 2 and 3 it going well,but when from page if i switch to page 2 it is raising an exception its here

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.ArrayList.get_Item(Int32 index) at System.Web.UI.WebControls.GridViewRowCollection.get_Item(Int32 index) at UserPanel_Docters.grdView_RowCommand(Object sender, GridViewCommandEventArgs e)
my code is


C#
protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Convert.ToInt32(e.CommandArgument);
        try
        {
            GridViewRow row =grdView.Rows[index];
            Label lbl = (Label)row.Cells[0].FindControl("lblName");
            Name = lbl.Text;
            lblDocname.Text = Name;
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdView.PageIndex = e.NewPageIndex;
        bindgrid();
    }
Posted
Updated 4-Oct-13 19:18pm
v2

hello friend

i think this will help you as you want....


Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index[^]

happy top help!!!
 
Share this answer
 
If you are still having the problem and not able to resolve it, please refer this link and the follow step by step. I think this would resolve your problem.

http://www.c-sharpcorner.com/UploadFile/rohatash/gridview-paging-sample-in-Asp-Net/[^]
 
Share this answer
 
CommandName="n" //Insert following line source page behind CommandArgument


protected void grdView_RowCommand(object sender, GridViewCommandEventArgs e)
{

if(e.CommandName=="n")
{
int index = Convert.ToInt32(e.CommandArgument);
try
{
GridViewRow row =grdView.Rows[index];
Label lbl = (Label)row.Cells[0].FindControl("lblName");
Name = lbl.Text;
lblDocname.Text = Name;
}
catch (Exception ex)
{
Response.Write(ex);
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900