Ticket T1285709
Visible to All Users

Issues when adding columns dynamically - Hiding columns and persisting column widths

created 7 days ago

Hi

We have an Aspxgrid that is bound to a Sql Datasource. Some columns are defined in the aspx markup while other columns are added in the DataBinding event as they are unknown at design time. Below is how we are adding the columns

Visual Basic
Private Sub grid_DataBinding(sender As Object, e As EventArgs) Handles grid.DataBinding grid.DataSource = dsWip Dim dw As DataView = CType(dsWip.Select(DataSourceSelectArguments.Empty), DataView) If dw IsNot Nothing Then Dim dataTable As DataTable = dw.ToTable() If dataTable.Rows.Count > 0 Then ' Loop through the columns and add dynamic columns For Each column As DataColumn In dataTable.Columns ' Skip the standard columns If IsNotInColumnList(column.ColumnName) Then Dim CKcolumn As New DevExpress.Web.GridViewDataCheckColumn() CKcolumn.ReadOnly = True CKcolumn.FieldName = column.ColumnName CKcolumn.Caption = column.ColumnName CKcolumn.PropertiesCheckEdit.ConvertEmptyStringToNull = True CKcolumn.PropertiesCheckEdit.NullDisplayText = "No" CKcolumn.Settings.AllowHeaderFilter = DevExpress.Utils.DefaultBoolean.False CKcolumn.Settings.ShowFilterRowMenu = DevExpress.Utils.DefaultBoolean.False CKcolumn.Settings.AllowAutoFilter = DevExpress.Utils.DefaultBoolean.False CKcolumn.Settings.ShowInFilterControl = DevExpress.Utils.DefaultBoolean.False grid.Columns.Add(CKcolumn) End If Next End If End If End Sub

This works fine, but I am having 2 problems as a result. First when a user attempts to hide one of the dynamically added columns via the "Customization dialog" the columns are not added. Columns defined in the aspx page will hide, but not those added dynamically.

Secondly, even though SettingsCookies-Enabled="True", changes in column widths are not being persisted.

Any guidance would be appreciated.

Comments (1)

    HiAlexander

    That did the trick. Thanks for the quick response.

    Peter

    Answers approved by DevExpress Support

    created 6 days ago

    Hi Peter,

    Thank you for the code snippet. At first glance, your configuration is valid. I assume the issue occurs due to some code we didn't take into account. Such issues may arise if you bind the Grid in an incorrect life cycle event. Generally, we recommend binding the Grid in Page_Init as we did in the following example: Grid View for ASP.NET Web Forms - How to create columns and bind the control to different data sources at runtime

    If you need further assistance, please share a sample project, so that we can analyze and debug the issue locally. Please note that we don't need the entire application for testing. A simplified project that illustrates the problematic area will be sufficient. You can use the example that I shared as a starting point and apply your implementation.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.