gberg927
gberg927

Reputation: 1686

ASP.NET DataContext GridView Paging

Possible Duplicate:
The data source does not support server-side data paging

I have a GridView that is databound to returned results using a LINQ Query. I have enabled paging on the gridview as there are about 300 records returned.

I created a search function that generates general SQL Queries and returns a result. However I get the following error when it is executed.

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

Here is my code that performs the SQL Search.

    IEnumerable<equipment> result = db.ExecuteQuery<equipment>(SQLQuery);
    equipmentGrid.DataSource = result;
    equipmentGrid.DataBind();

This is the gridview code:

<asp:GridView ID="equipmentGrid" OnPageIndexChanging="equipmentGrid_PageIndexChanging" runat="server">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                    <a href="details.aspx?EQCN=<%# DataBinder.Eval(Container.DataItem, "EQCN") %>">Details</a> | 
                    <a href="edit.aspx?EQCN=<%# DataBinder.Eval(Container.DataItem, "EQCN") %>">Edit</a> | 
                    <a href="delete.aspx?EQCN=<%# DataBinder.Eval(Container.DataItem, "EQCN") %>">Delete</a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

And the OnPageIndexChanging function

protected void equipmentGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    equipmentGrid.PageIndex = e.NewPageIndex;
    equipmentGrid.DataBind();
}

Thanks so mucH!!!!!

Upvotes: 1

Views: 966

Answers (2)

Glory Raj
Glory Raj

Reputation: 17701

Try this one ...

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

    // Add here your method for DataBinding
     BindGridControl();

    gridView.PageIndex = e.NewPageIndex;
    gridView.DataBind();
 }

Without the databinding method you won't get the paged result.

Upvotes: 0

joelmdev
joelmdev

Reputation: 11773

You need to set the Gridview's AllowPaging property to true:

<asp:GridView ID="equipmentGrid" OnPageIndexChanging="equipmentGrid_PageIndexChanging" runat="server" AllowPaging="true">

And you may need to call ToList() on your LINQ query. You could also setup a LINQ datasource in the aspx.

Upvotes: 0

Related Questions