Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
Calling Columns.Clear results in dynamically added columns not rendering when paging
posted

Hi,

I have a multipurpose page that display all sorts of data sources in a WebDataGrid.  

The grid has an unbound dynamically added WebDataGridCheckBox column added via a TemplateDataField in code.  
The rest of the columns are created by adding BoundDataField objects to the Columns collection (nothing is defined declarative)

All works well, including paging, until I change the data source.

When switching data sources, I first call ClearDataSource and then Columns.Clear before recreating the unbound and then bound columns.

The new grid renders fine, however when paging, the Checkbox control disappears (although the header is still there).

If I do not call Columns.Clear the problem does not happen, however if the data sources have different columns in them, this causes a problem.

Can anyone help with this?

Thanks 

Code Snippets:
 

    Public Function Reset() As Boolean
        With Grid
            .ClearDataSource()
            .Columns.Clear()
            If Not IsNothing(.Behaviors.Sorting) Then Behaviors.Sorting.SortedColumns.Clear()
            If Not IsNothing(.Behaviors.Filtering) Then Behaviors.Filtering.ClearBehaviorColumnInfo()
            BuildColumns()
        End With
        Return True
    End Function

 

    Private Function BuildColumns() As Boolean
        Dim chkSel = Grid.Columns.FromKey("chkSel")
        If chkSel Is Nothing Then
            Dim chk As New WebDataGridCheckbox("chkSel")
            Dim tdf As New TemplateDataField(False)
            tdf.ItemTemplate = chk
            tdf.Key = chk.Key
            tdf.Width = New Unit(30)
            tdf.Hidden = Not ShowCheckbox
            Grid.Columns.Add(tdf)
        End If
        Return BuildDataColumns()
    End Function

 

Parents
No Data
Reply
  • 29417
    Offline posted

    Hello JamesKydd ,

     

    Thank you for posting in our forum.

    Are you clearing the grid’s columns over the ajax callbacks initiated by the paging as well?

    Generally you should clear them only when changing the data source.

    Also could you let me know in which event of the page lifecycle you’re clearing the data source and columns and recreating them?

    Generally it would be best to be done early in the lifecycle for example in Page Init.

     

    I’m looking forward to your reply.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer

    Infragistics, Inc.

    http://es.infragistics.com/support

     

Children