views:

330

answers:

2
+1  Q: 

Gridview Paging

I've got a gridview that is bound to a dataview in the codebehind. The datasource is actually powershell, so I'm processing the data myself. This works fine and displays the result how I want. However, when I try to enable paging, I get this error when opening the page:

The table must contain row sections in order of header, body, then footer.

Any idea why this is happening?

Heres the code for my binding:

      mbGrid.DataSource = MailBoxManager.Instance.getDataTable();
      mbGrid.EnableSortingAndPagingCallbacks = true;
      mbGrid.AllowPaging = true;

And the code that populates the datatable is:

public DataTable getDataTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Name", typeof(string)));
        dt.Columns.Add(new DataColumn("Email", typeof(string)));

        foreach (Mailbox mb in MbList)
        {
            DataRow dr;
            dr = dt.NewRow();
            dr["Name"] = mb.Name;
            dr["Email"] = mb.PrimaryEmail;
            dt.Rows.Add(dr);
        }
        return dt;
    }
A: 

There were 2 issues here for anyone that comes across this issue. Firstly, for some reason, setting the paging settings in the aspx page, rather than the code behind fixed the first error, not really sure why. I then recieved another error, because the datasource I'm using is not a sql datasource, its a custom one, so I had to define the code for the gridview_pageIndexChanging method, once I did that, it worked great. The code for that is quite straight forward:

 protected void grid_PageIndexChanging1(object sender, 
                                        GridViewPageEventArgs e)
   {
        grid.PageIndex = e.NewPageIndex;
        grid.DataBind();
   }
Sam Cogan
A: 

An out of the box GridView control to deal with this type of problems

YordanGeorgiev