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

How do you allow paging when a grid is programmatically created by a user action

3 Answers 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ewald Hofman
Top achievements
Rank 1
Ewald Hofman asked on 08 Jun 2011, 06:54 AM

When I programmatically add a grid in the Page Init event, I understand how I can create the paging and it works.

However if the grid is not created in the Page Init, but in the Ribbon Buttonclicked event the paging command on the grid is not working. How should I enable this.

Private Sub ribbon_ButtonClick(sender As Object, e As Telerik.Web.UI.RibbonBarButtonClickEventArgs) Handles ribbon.ButtonClick
Dim radGrid = New RadGrid() With {
.AllowCustomPaging = True,
.AllowFilteringByColumn = True,
.AllowPaging = True,
.AllowSorting = True,
.AutoGenerateColumns = True,
.ID = "myGrid",
.PageSize = 4,
.ShowGroupPanel = True,
.ShowStatusBar = True,
.VirtualItemCount = 20,
.Width = Unit.Percentage(95)
}
AddHandler radGrid.NeedDataSource, Sub(_sender As Object, _e As GridNeedDataSourceEventArgs) RefreshData(CType(_sender, RadGrid))
AddHandler radGrid.PageIndexChanged, Sub(_sender As Object, _e As GridPageChangedEventArgs) RefreshData(CType(_sender, RadGrid))
AddHandler radGrid.PageSizeChanged, Sub(_sender As Object, _e As GridPageSizeChangedEventArgs) RefreshData(CType(_sender, RadGrid))
phGrid.Controls.Add(radGrid)
RadAjaxManager.AjaxSettings.AddAjaxSetting(radGrid, radGrid)
End Sub
Private Sub RefreshData(grid As RadGrid)
grid.DataSource = New List(Of String)({grid.CurrentPageIndex, grid.PageSize})
End Sub

3 Answers, 1 is accepted

Sort by
0
Accepted
Iana Tsolova
Telerik team
answered on 10 Jun 2011, 04:01 PM
Hi Ewald,

The grid paging is not working because the grid is created too late in the page lifecycle and for that reason it is not initialized properly. Therefore cannot work properly. What you can try in your case is to recreate the grid on the subsequent postback and see if it works. If not, then you should find a way to create the grid on Page_Init. You can for instance use a hidden field as a flag. On the client set its value so on the server Page_Init you are able to see if you should create the grid or not.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Ewald Hofman
Top achievements
Rank 1
answered on 12 Jun 2011, 10:49 PM
Thanks for your suggestion. It now works with a hidden field.

However, the grid that is created based on the hidden field is different on every postback. It has a different datasource and different columns. The different datasource I have handled by disabling the ViewState, but I have problems with the different columns.

In my first attempt, I did not call the radGrid.Columns.Clear() method so the columns that were shown in the grid grew rapidly. When I add the Clear method call before I dynamically add all the columns I get an IndexOutOfRange exception. I think because there is some information in ViewState(?) that cannot find the column anymore.

Could you please elaborate what is happening and how I can work around this?
0
Accepted
Iana Tsolova
Telerik team
answered on 13 Jun 2011, 10:25 AM
Hello Ewald,

Can you confirm you are adding the grid on Page_Init? You can try following the steps described in this article and see if it works for you.

Greetings,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Ewald Hofman
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Ewald Hofman
Top achievements
Rank 1
Share this question
or