Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to bind my data Gridview but it throw an error. i allow paging when i click on new page e.g 1.2.3 then the above error throw here is my code. the one is page index change and the other one is my method of BindGrid. the error come when i click one new page 2 or 3 etc

C#
protected void DataGrid1_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e)
    {

        DataGrid1.CurrentPageIndex = e.NewPageIndex;
        DataGrid1.DataSource = Session["data"] as DataTable;
        DataGrid1.DataBind();
    }
    private void BindGrid()
    {
        DataTable data = storedProcedureManager.sp_inactiveFiles(
                providerID,
                 days, CaseTypeID, CollectorID, user.UserRegID);
        lblMsg.Text = data.Rows.Count + " Record's Found.";
        log.Info(lblMsg.Text);
        Session["data"] = data;
        DataGrid1.DataSource = data;
        DataGrid1.DataBind();

        log.Info("Report Displayed.");

    }
if (!IsPostBack)
       {

           BindGrid();
       }
Posted
Updated 24-Aug-15 20:26pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Aug-15 2:24am    
What's unclear here? If you Count item, you index can be 0 to Count - 1. Anyway, this is not even a question.
—SA
Razim Khan 25-Aug-15 8:44am    
@sergey Alexandrovich it didnt work for me
virusstorm 25-Aug-15 13:37pm    
Make sure you hit the "Reply" button next to the person's name, otherwise they won't know you've responded.

As to your error, "e.NewPageIndex" has a value less the zero or has a value greater then the number of pages in "DataGrid1". Set a break point there and see what the value is and also how many pages are in "DataGrid1".

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