Search code examples
.neteventsgridviewtelerikradgrid

Dynamic Paging Bar Position in Telerik RadGrid Component


I've got a component, inheriting from Telerik RadGrid (.NET) and I want to set the PagerStyle.Position to GridPagerPosition.TopAndBottom if I've got more than 50 rows on that page or to GridPagerPosition.Bottom otherwise.

I've tried several events that are called once per page load (not once per item) like OnNeedDataSource, ControlPreRender, OnDataPropertyChanged but I cannot reliably get the Count of the rows. It comes back as -1 or zero even though the DataSource object is populated. I might be too early in those events? Checking the component's life cycle didn't help either.

Where to put the if (count > 50) ...?


Solution

  • I ended up creating a custom pager because I needed some special features. In there it was straight forward to call the GridPagingManager (_pagingMgr):

    _tblView.PagerStyle.Position = _pagingMgr.LastIndexInPage - _pagingMgr.FirstIndexInPage > 50 
                ? GridPagerPosition.TopAndBottom 
                : GridPagerPosition.Bottom;`
    

    Done!