The data source does not support server-side data paging

Viewed 63790

I have a GridView on my screen and need it to allow paging.

Markup:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
  AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
  <Columns>
    <asp:BoundField DataField="appID" HeaderText="appID" SortExpression="appID" />
  </Columns>
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
  SelectMethod="GetBookingId" 
  TypeName="AppointmentRepository">
  <SelectParameters>
    <asp:Parameter Name="maximumRows" Type="Int32" />
    <asp:Parameter Name="startRowIndex" Type="Int32" />
  </SelectParameters>
</asp:ObjectDataSource>

Code-behind:

ObjectDataSource1.SelectParameters["maximumRows"].DefaultValue = "10";
ObjectDataSource1.SelectParameters["startRowIndex"].DefaultValue = "0";

LINQ query:

public IQueryable<tblAppointment> GetBookingId(int maximumRows, int startRowIndex)
{
    var result = (FROM a IN dc.tblAppointments
                  SELECT a).Skip(startRowIndex).Take(maximumRows);
}

However I receive this error:

The data source does not support server-side data paging.

What am I doing wrong?

8 Answers

Try this article https://www.aspsnippets.com/Articles/ASPNet-GridView-The-data-source-does-not-support-server-side-data-paging.aspx

in summary try to use these lines

private void BindGrid()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT CustomerId, ContactName, Country FROM Customers"))
        {
            cmd.Connection = con;
            con.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                GridView1.DataSource = sdr;
                GridView1.DataBind();
            }
            con.Close();
        }
    }
}

protected void OnPaging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    this.BindGrid();
}

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
OnPageIndexChanging="OnPaging">
<Columns>
    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
    <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
    <asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>

Related