Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
After changing index of the page row command is giving exception "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

My code is "
C#
int index1 = Convert.ToInt32(e.CommandArgument);
            GridViewRow rows = gvd.Rows[index1];"

after page index changed that page have 2 rows but commandArgument value is 11 how to over come this issue please help me ...
Posted
Updated 11-Jun-12 2:32am
v2

What and why are you doing this: GridViewRow rows = gvd.Rows[index1];"

Pagination is not implemented like this. All you need to do is increase the page count and rebind the grid. .NET will automatically show the correct rows.
Refer: MSDN: GridView.PageIndexChanged Event[^]
 
Share this answer
 
Comments
aamear 11-Jun-12 8:49am    
page size is six and index value is 11 so rows[11] is exceeding any array size
Sandeep Mewara 11-Jun-12 9:05am    
Thats what I said. You cannot force page to move on if there are no as many records.
Hi,
try this:

Add the following in your html code:

VB
<asp:GridView ID="gvd" runat="server" AllowPaging="True"
        onpageindexchanging="gvd_PageIndexChanging"


and the following code in codebehind:

C#
protected void gvd_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvd.PageIndex = e.NewPageIndex;
        gvd.DataBind();
    }


Thank you
 
Share this answer
 
Comments
aamear 11-Jun-12 8:44am    
ya i have done it before but still it is giving an exception

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