Search code examples
c#asp.netinfragisticswebdatagrid

WebHierarchicalDatagrid Shows No Data on Initial PageLoad


I have a WebHierarchicalDatagrid where I manually create the columns in my PageLoad() event. None of my columns shows on initial page load, even though the datasource has data that matches the columns. (I DO set and bind after the columns are created/added to the grid). If I refresh (PostBack), then they show. I have cleared and reset the grid many ways.

If I define columns in markup then the initial page load works of course, but I need to dynamically create columns based on my user roles and if I clear and recreate the desired columns in my page load, page prerender, etc I get a viewstate error.

Seems that you cannot use markup and codebehind to define a grid. Would not be a problem, but I have a custom (user control) pager template defined in markup and I spent days trying to get create that in codebehind given I cannot just point the codebehind pager creation to use an existing user control. Total catch-22.

Infragistics grids are just too tweaky to deal with anymore. If you stay on the straight and narrow, they are good, but stray off the path and you are in big trouble!


Solution

  • AutoGenerateBands and AutoGenerateColumns should be set to false. Also, I don't know whether you are using GridView to configure the grid or not, although I wanted to let you know that WebHierarchicalDataGrid.Columns collections is relevant to the root band of the columns defined at designed time or from the markup. As for the columns that are auto generated, they could be accessed from WebHierarchicalDataGrid.GridView.Columns.

    As I understand you are creating the columns from Page_Load event, try to do that on WHDG_Init. I am just curious what would be the result.

    protected void WebHierarchicalDataGrid1_Init(object sender, EventArgs e)
    {
        WebHierarchicalDataGrid1.DataSource = new TestData().GetData();
        WebHierarchicalDataGrid1.DataKeyFields = "ID";
    
        WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("ID", "ID"));
        WebHierarchicalDataGrid1.Columns.Add(CreateNewBoundDataField("Name", "Name"));
        WebHierarchicalDataGrid1.Bands.Add(CreateNewBand("ChildBand_0", "Child", "ChildID"));
    
        WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ChildID", "ChildID"));
        WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("ID", "ID"));
        WebHierarchicalDataGrid1.Bands["ChildBand_0"].Columns.Add(CreateNewBoundDataField("Address", "Address"));
    
        WebHierarchicalDataGrid1.Bands["ChildBand_0"].Behaviors.CreateBehavior<Filtering>();
    }
    
    public static BoundDataField CreateNewBoundDataField(string columnName, string headerText)
    {
        BoundDataField boundDataField = new BoundDataField();
        boundDataField.DataFieldName = columnName;
        boundDataField.Key = columnName;
        boundDataField.Header.Text = headerText;
        return boundDataField;
    }
    
    public static Band CreateNewBand(string key, string dataMember, string dataKeyField)
    {
        Band band = new Band();
        band.AutoGenerateColumns = false;
        band.Key = key;
        band.DataMember = dataMember;
        band.DataKeyFields = dataKeyField;
        return band;
    }