RadGrid Paging does not work fine after changing page
Solution 1
After a long time I found the solution, the problem involved 2 minor issues :
1.I had both DataSource (in code) and DataSourceID (property) set and they didn't work together well
2.I had both AllowPaging and AllowCustomPaging set to true, when they are both true neither works :) that's the telerik team you know, but they are great I was kidding
Solution 2
You will have to set up following attributes of the grid in design
<telerik:RadGrid ID="grdName"
AllowPaging="True"
AllowCustomPaging="True"
VirtualItemCount="0" PageSize="15" >
Populate grid on load vb.net
Private Sub PopulateGridOnLoad()
grdName.DataSource = source ' your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
grdName.Rebind()
End Sub
Populate grid on load c#.net
private void PopulateGridOnLoad()
{
grdName.DataSource = source;
// your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total;
//your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
grdName.Rebind();
}
Override NeedDatasource vb.net
Protected Sub grdName_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdName.NeedDataSource
grdName.DataSource = source ' your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total 'your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex
'Donot rebind here
End Sub
Override NeedDatasource c#
protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
grdName.DataSource = source;
// your datasource type
grdName.MasterTableView.VirtualItemCount = source.Total;
//your datasource type total/count
grdName.CurrentPageIndex = grdName.MasterTableView.CurrentPageIndex;
//Donot rebind here
}
![Mahdi Tahsildari](https://i.stack.imgur.com/mJEJb.jpg?s=256&g=1)
Mahdi Tahsildari
Love programming, it's fun. MCP since 2011. C#, ASP.net MVC Core, SQL; NodeJs, Angular, HTML, CSS, Javascript. Currently focused on ASP.Net Core and Unit Testing.
Updated on July 14, 2022Comments
-
Mahdi Tahsildari almost 2 years
I have a RadGrid in my ASP.Net app and I have set the AllowPaging to True and PageSize to 10, now it load 10 items per RadGridPage which is what I wanted, but as soon as I press Next Page button (Arrow look button) nothing loads and RadGrid gets empty. How can I make it work normal?
protected void Page_Load(object sender, EventArgs e) { PopulateGridOnLoad(); } private void PopulateGridOnLoad() { rgCustomers.DataSource = odsCustomers; // your datasource type rgCustomers.MasterTableView.VirtualItemCount = 28; //your datasource type total/count rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex; rgCustomers.Rebind(); } protected void grdName_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { rgCustomers.DataSource = odsCustomers; // your datasource type rgCustomers.MasterTableView.VirtualItemCount = 28; //your datasource type total/count rgCustomers.CurrentPageIndex = rgCustomers.MasterTableView.CurrentPageIndex; //Donot rebind here } protected void btnLoad_Click(object sender, EventArgs e) { odsCustomers.SelectParameters["CustomerFullName"].DefaultValue = txtFullName.Text; odsCustomers.SelectParameters["CustomerMelliCode"].DefaultValue = txtMelliCode.Text; odsCustomers.SelectParameters["CustomerHomeAddress"].DefaultValue = txtHomeAddressPart.Text; odsCustomers.SelectParameters["CustomerWorkAddress"].DefaultValue = txtWorkAddressPart.Text; rgCustomers.DataSource = odsCustomers; rgCustomers.DataBind(); }