Deleting records from a Telerik RadGrid not updating the pager

When I was deleting rows from the Telerik RadGrid, the page count used for paging on the bottom left wasn’t updating. So if I had 21 records, with a setting of 10 records per page, I would see 3 pages. If I deleted 10 records, I would expect that the pages listed would be reduced to 2, but it wasn’t – it was staying at three. As Mr. Smith from Lost in Space would say, “The pain, the pain”.

My solution was to create a global page variable to hold the latest number of rows:

int currentRows  = 0;

In the function that loads the grid (creatively called LoadGrid), I added code to update the currentRows  variable with the latest count of items from the database. So whenever the count was updated, my code would detect the latest count of items:

List<MyItem> Items = GetThoseObjectsDude();
 currentRows = Items.Count;

Finally, during the Page_PreRender event, I added a check to see if the count was updated. If so, then it updated the RadGrid’s VirtualItemCount property. When the RadGrid was rebound, the page count would be updated, too:

protected void Page_PreRender(object sender, EventArgs e)
 if (currentRows > 0)
 gridItems.VirtualItemCount = currentRows;
currentRows = 0;
  1. #1 by Erik V on February 16, 2012 - 7:34 pm

    awesome, Scott! Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: