The .aspx:
<asp:GridView ID="gvFirst" runat="server" AutoGenerateColumns="false"
AllowPaging="true"
ondatabound="gvFirst_DataBound" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ProductID"/>
<asp:BoundField DataField="Name" HeaderText="ProductName" />
</Columns>
<PagerTemplate>
<asp:Panel ID="pnlPager" runat="server">
</asp:Panel>
</PagerTemplate>
</asp:GridView>
The .cs:
public class Productinformation
{
public int PID
{
get;
set;
}
public string PName
{
get;
set;
}
}
using (NorthWindDataContext _NorthWindDataContext = new NorthWindDataContext())
{
Proinfo = new List<Productinformation>();
Proinfo = (from p in _NorthWindDataContext.Products
select new Productinformation
{
PID = p.ProductID,
PName = p.ProductName,
}).ToList();
gvFirst.DataSource = Proinfo.Take(PageSize) ;
gvFirst.DataBind();
}
Proinfo variable is declared globally. Now When i run this code, it shows me the following error :
the data source does not support server-side data paging
If i use var type of variable then it is worked but
we can’t declare var type of variable globally,so if i used it, then i have to call this method every time in paging. and i don’t want to use Objectdatasource.
You must return a List to the
gvFirstusingToList()method. So try this:Explanation:
Because on the
gvFirstyou set the propertyAllowPaging="true"than the paging can be used with any data source object that implementsICollectioninterface.ProInfo.Take(PageSize)returns anIEnumerableand this is why you need to call theToList()method.