This is a migrated thread and some comments may be shown as answers.

RadGrid Paging problem

4 Answers 167 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Divyang
Top achievements
Rank 1
Divyang asked on 25 Jul 2011, 02:52 PM
I am not getting updated pageindex when navigating from page to page. it shows previous page number, not current one which is clicked.
Master.SearchResults is radGrid
Following is configuration of grid on aspx.     <telerik:RadGrid ID="SearchResultsGrid" runat="server" EnableViewState="True"             Height="100%" AutoGenerateColumns="false" AllowPaging="true" AllowCustomPaging="true"             AllowSorting="True" AllowMultiRowSelection="True" GridLines="None"              Skin="Telerik"  OnItemCommand="SearchResultsGrid_ItemCommand"             OnNeedDataSource="SearchResultsGrid_NeedDataSource" PageSize="50" Width="721" >             <MasterTableView EnableNoRecordsTemplate="true" TableLayout="Fixed" DataKeyNames="AssignmentId">




protected void SearchResultsGridNeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            try
            {
                    LoadSearchResults();
            }
            catch (Exception ex)
            {
                HandleException(Master.ErrorMessagePanel, AssignmentErrorMessages.FIND_ASSIGNMENTS, string.Empty, MessageStatus.Error, ex);
            }
        }

 private void LoadSearchResults(bool dataBind = false)
        {
            if (rdoObjectType.SelectedItem == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(selNames.SelectedValue))
            {
                return;
            }
            int objectId = int.Parse(rdoObjectType.SelectedItem.Value);
            int nameId = int.Parse(selNames.SelectedValue);
            List<SelectListDto> clientNames = (List<SelectListDto>)GetClientNames(objectId, selNames.Text);
            int objectTypeId = int.Parse(clientNames.Single(c => c.Value == int.Parse(selNames.SelectedValue)).ExtraField);
            int statusId = int.Parse(rdoStatus.SelectedValue);
            AssignmentSearchResultDto assignments  = FindAssignment(objectTypeId, objectId, nameId, statusId);
 
            Master.SearchResults.VirtualItemCount = assignments.TotalItems;
            Master.SearchResults.AllowCustomPaging = true;
            Master.SearchResults.DataSource = assignments.Assignments;
            Master.SearchResults.PageIndexChanged += RadGrid1_PageIndexChanged;
        }

 private AssignmentSearchResultDto FindAssignment(int objectTypeId, int objectId, int personId, int status)
        {
            int startRowIndex = Master.SearchResults.CurrentPageIndex * Master.SearchResults.PageSize;
            int maximumRows = Master.SearchResults.PageSize;
            AssignmentSearchResultDto assignments;
            using (Assignment assignment = new Assignment())
            {
                assignments = assignment.FindAssignment(objectTypeId, objectId, personId, status, agencyId, startRowIndex, maximumRows);
            }
            return assignments;
        }



4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2011, 06:04 AM
Hello Divyang,

You can try the following code snippet to get the CurrentPageIndex. Hope this helps.

C#:
RadGrid1.PageIndexChanged += new GridPageChangedEventHandler(RadGrid1_PageIndexChanged);
void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
 {
   int index = SearchResultsGrid.MasterTableView.CurrentPageIndex;
 }

Thanks,
Princy.
0
Divyang
Top achievements
Rank 1
answered on 26 Jul 2011, 10:11 AM
My question was "PageIndexChanged" executes after needdatasource event and becuase of that needdatasource event has no updated pageindex. Problem still exists.
0
Shinu
Top achievements
Rank 2
answered on 26 Jul 2011, 11:09 AM
Hello Divyang,

Try the folowing code snippet in PreRender to get the current PageIndex.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  string PageIndex =SearchResultsGrid.MasterTableView.CurrentPageIndex.ToString();
}

Thanks,
Shinu.
0
Accepted
Vasil
Telerik team
answered on 26 Jul 2011, 02:48 PM
Hello Divyang,

CurrentPageIndex should be the new one when NeedDataSource is fired unless the grid tries to rebind itself because of manually called Rebind() method too early.
You could see this demo, where CurrentPageIndex is used inside the NeedDataSource, I think in the demo the custom paging is working fine and you could follow the same approach:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/custompaging/defaultcs.aspx

Kind regards,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
General Discussions
Asked by
Divyang
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Divyang
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or