entity-frameworklistgridviewdata-paging

List<T> paging asp.net


Using a three-tier architecture, I have a list of objects

 List<object> careerList = new List<object>();
            ModuleDTO module = new ModuleDTO();
            careerList = module.getDegreeCodeByQualification(qualificationCode);

which I then add to a gridview like so:

 gridViewMaster.DataSource = careerList;
            gridViewMaster.DataBind();

What I'd like to do is then enable paging on the gridview. My gridview so far is:

 <asp:GridView ID="gridViewMaster" runat="server" 
        AutoGenerateColumns="False" GridLines="None"
        BorderWidth="1px" CellPadding="2" DataKeyNames="Grouping" 
        ForeColor="Black"
            onrowdatabound="gridViewMaster_RowDataBound" CssClass="mGrid" PagerStyle-CssClass="pgr"  
AlternatingRowStyle-CssClass="alt" OnPageIndexChanging="gridView_PageIndexChanging" 
                AllowPaging="True" >

Is it possible to do enable paging on a list's without having to change that list to a Datatable or Dataview? If there is a way, this would help a lot.

So far my events are as follows:

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gridViewMaster.PageIndex = e.NewPageIndex;
        List<object> careerList = new List<object>();
            ModuleDTO module = new ModuleDTO();
            careerList = module.getDegreeCodeByQualification(qualificationCode);
            ModalProgress.Show();
            System.Threading.Thread.Sleep(1000);
            JobPanel.Visible = true;
            gridViewMaster.DataSource = careerList.Distinct();
            gridViewMaster.DataBind();
    }

Someone PLEASE HELP ME!!! Thank you


Solution

  • I have your code working, with a GridView paging from a List databinding. Message me if you have any more issues after trying the following checks:

    1. Make sure this code returns a list of items with a property named "Grouping" because you have it listed as a DataKeyName in your GridView like so:

      careerList = module.getDegreeCodeByQualification(qualificationCode);

    2. My GridView code looks like this:

          <asp:GridView ID="GridView1" runat="server" GridLines="None" BorderWidth="1px" CellPadding="2" DataKeyNames="Grouping" 
          ForeColor="Black" AllowPaging="True" 
          onpageindexchanging="GridView1_PageIndexChanging" AutoGenerateColumns="true" PageSize="2">
      </asp:GridView>
      

    ... note the new "PageSize" and "AutoGenerateColumns" attributes that I added.

    Hope that helps.