Dears,
I am working on a composite custom control contains a radGrid control, I faced the following problem in the RadGrid Paging,
i have set the RadAjaxManager to enable the Ajax paging for my grid so that it shouldn't postback on each page number change,
unfortunately, it is doing postback on each page index change and it is not passing by the GridNeedDataSourceEventHandler
Please check below code sample and help me to fix this issue,
Any help will be highly appreciated,
| protected override void OnInit(EventArgs e) |
| { |
| //grdTransactionsList |
| grdTransactionsList.ID = "grdTransactionsList"; |
| grdTransactionsList.Skin = "Office2007"; |
| grdTransactionsList.AutoGenerateColumns = false; |
| grdTransactionsList.AllowPaging = true; |
| grdTransactionsList.AllowCustomPaging = true; |
| grdTransactionsList.PageSize = Constants.PageSize; |
| grdTransactionsList.Visible = true; |
| grdTransactionsList.NeedDataSource += new GridNeedDataSourceEventHandler(grdTransactionsList_NeedDataSource); |
| grdTransactionsList.PagerStyle.Mode = GridPagerMode.NumericPages; |
| grdTransactionsList.MasterTableView.GridLines = GridLines.None; |
| grdTransactionsList.MasterTableView.AutoGenerateColumns = false; |
| grdTransactionsList.MasterTableView.TableLayout = GridTableLayout.Auto; |
| InitilizeTransactionsListColumns(); |
| grdTransactionsList.ClientSettings.Selecting.AllowRowSelect = true; |
| grdTransactionsList.ClientSettings.EnableRowHoverStyle = true; |
| //Check if there is already added ScriptManager to this Page, Only one Script Manager Instance can be in the page |
| if (ScriptManager.GetCurrent(this.Page) == null) |
| { |
| scriptManager = new ScriptManager(); |
| scriptManager.ID = "ScriptManager1"; |
| } |
| if (RadAjaxManager.GetCurrent(this.Page) == null) |
| { |
| radAjaxManager = new RadAjaxManager(); |
| radAjaxManager.ID = "RadAjaxManager"; |
| radAjaxLoadingPanel = new RadAjaxLoadingPanel(); |
| radAjaxLoadingPanel.ID = "pnlRadAjaxLoadingPanel"; |
| radAjaxLoadingPanel.Height = new Unit(50); |
| radAjaxLoadingPanel.Width = new Unit(50); |
| radAjaxLoadingPanel.Transparency = 30; |
| Image imgLoading = new Image(); |
| imgLoading.ID = "imgLoading"; |
| radAjaxLoadingPanel.Controls.Add(imgLoading); |
| radAjaxManager.DefaultLoadingPanelID = radAjaxLoadingPanel.ID; |
| } |
| } |
| protected override void CreateChildControls() |
| { |
| if (scriptManager != null) |
| Controls.Add(scriptManager); |
| if (radAjaxManager != null) |
| Controls.Add(radAjaxManager); |
| if (radAjaxLoadingPanel != null) |
| Controls.Add(radAjaxLoadingPanel); |
| if (RadAjaxManager.GetCurrent(this.Page) != null) |
| { |
| AjaxSetting ajaxSetting = new AjaxSetting (grdTransactionsList.ID); |
| ajaxSetting.UpdatedControls.Add(new AjaxUpdatedControl(grdTransactionsList.ID, radAjaxLoadingPanel.ID)); |
| RadAjaxManager.GetCurrent(this.Page).AjaxSettings.Add(ajaxSetting); |
| } |
| Controls.Add(new LiteralControl("<table>")); |
| Controls.Add(new LiteralControl(" <tr>")); |
| Controls.Add(new LiteralControl(" <td>")); |
| Controls.Add(grdTransactionsList); |
| Controls.Add(new LiteralControl(" </td>")); |
| Controls.Add(new LiteralControl(" </tr>")); |
| Controls.Add(new LiteralControl("</table>")); |
| } |
| protected void grdTransactionsList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| if (!Page.IsPostBack) |
| return; |
| else |
| { |
| try |
| { |
| int totalRecords = 0; |
| grdTransactionsList.DataSource = Presenter.GetTransactionsList(out totalRecords); |
| grdTransactionsList.VirtualItemCount = totalRecords; |
| } |
| catch (JoPayBusinessException ex) |
| { |
| ShowError(ex); |
| } |
| } |
| } |
| //Presenter.GetTransactionsList(out totalRecords) will call below method |
| public void SetTransactionsGrid(IList<TransactionSearch> paymentTransactions, int totalRecords) |
| { |
| grdTransactionsList.DataSource = paymentTransactions; |
| grdTransactionsList.VirtualItemCount = totalRecords; |
| grdTransactionsList.DataBind(); |
| } |