Please how any I resolve this issue?
 
I am trying to modify my datalist view to have paging , I used the below code which I found on c-sharpconer, but I get error message when I click on the previous buttons, all other buttons work work.
The error message says:
Index -5 is either negative or above rows count. 
 
this is the aspx
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="PagininDataList.WebForm1" %>   
  2. "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3.    
  4. "http://www.w3.org/1999/xhtml">  
  5. "server">  
  6.       
  7.     "text/css">  
  8.         .style1  
  9.         {  
  10.             width: 672px;  
  11.         }  
  12.       
  13.   
  14.   
  15.     "form1" runat="server">  
  16.    
      
  17.     "height: 79px; width: 429px">  
  18.         "DataList1" runat="server">  
  19.           
  20.         

     Details 

      
  21.           
  22.         
  23.           
  24.    
  25.         My Custom Datalist Template here  
  26.           
  27.    
  28.           
  29.           
  30.          
  31.      
  32.   
  33.   
  34.     
  35.   
  36.         
  37.   
  38.             
  39.   
  40.                 
  41.   
  42.     
  43.   
  44.    
  45.   
  46.         "btnfirst" runat="server" Font-Bold="true" Text="<<" Height="31px"  
  47.                     Width="43px" onclick="btnfirst_Click" />
  48.   
  49.             "btnprevious" runat="server" Font-Bold="true" Text="<" Height="31px"  
  50.                     Width="43px" onclick="btnprevious_Click" />
  51.   
  52.                 "btnnext" runat="server" Font-Bold="true" Text=">" Height="31px"  
  53.                     Width="43px" onclick="btnnext_Click" />
  54.   
  55.                     "btnlast" runat="server" Font-Bold="true" Text=">>" Height="31px"  
  56.                     Width="43px" onclick="btnlast_Click" />
  57.   
  58.     
  
  •       
  •   
  •  
  •  This is the C# Code