WebGrid (6.0) Template Column Not Rendered Upon Load

3 replies. Last post: August 25, 2009 8:57 AM by A Yousif
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
A YousifMember

Our custom grid has a custom check box in a Template type column.  It's always the first column and always on the grid.  It's strange as it does not render, even though the code is created, when the grid is first loaded.  Once any post back is done via refresh grid data, sorting, grouping, etc. the check box is then rendered.  It makes no sense and I'm not sure what I'm missing.  Below are snippets that of our code:

        public override bool OnPrepareDataBinding(object dataSource)
        {
            if (Page != null)
            {
                bool bFirstFormat = false;

                if (!Page.IsPostBack)
                {
                    // retrieve the underlying structure
                    this.RetrieveStructure();

                    // load, if any, the saved grid layout from
                    // the database
                    LoadGridPreferences();

                    // if it's not an InterSoft post back
                    if (!this.IsFlyPostBack)
                    {
                        // and we have no layout loaded from the db
                        if (!HaveUserLayout)
                        {
                            // then create our columns structure
                            CreateColumnStructure(dataSource);

                            // this flag tells us we're loading the grid with the
                            // default formatting set from the database, i.e., the
                            // user has not made any changes that were saved/loaded
                            // from the db.
                            bFirstFormat = true;
                        }
                    }
                }

                FormatGrid(dataSource, bFirstFormat);
            }

            return base.OnPrepareDataBinding(dataSource);
        }

The CreateColumnStructure does this to create the check box column:

...
    this.Columns.Clear();

    // Add the row checker column...
    int iAddedAt = AddTemplateColumn(null);
...
    ClearCachedDataSource();

    return;

And all AddTemplateColumn does is this:

        public int AddTemplateColumn(string ColumnName)
        {
            ISNet.WebUI.WebGrid.WebGridColumn oCol = new ISNet.WebUI.WebGrid.WebGridColumn(ColumnName,ColumnName,ColumnName);
            oCol.ColumnType = ISNet.WebUI.WebGrid.ColumnType.Template;

            return this.Columns.Add(oCol);
        }

Once the columns are created, then we have a separate process that formats them.  We read info about the default grid layout from the database and set it up based on the returned info.  Whatever the case through, the check box columns always get created since this column is  not bound.  The code below gets hit regardless of whether the request is an update or not, so this is why I don't understand why it doesn't get rendered.

...
    // format the row checker column which is always the first one
    int iColIdx = 0;

    // remove and recreate the check box column
// note that I'm only doing the RemoveAt/Insert because of this
// rendering problem which I thought this may resolve, but it did not
// normally I would not have these two lines this.Columns.RemoveAt(iColIdx); this.Columns.Insert(iColIdx,new ISNet.WebUI.WebGrid.WebGridColumn()); this.Columns[iColIdx].ColumnType = ISNet.WebUI.WebGrid.ColumnType.Template; this.Columns[iColIdx].EditType = ISNet.WebUI.WebGrid.EditType.NoEdit; this.Columns[iColIdx].IsRowChecker = false; this.Columns[iColIdx].ShowInSelectColumns = ISNet.WebUI.WebGrid.SelectColumns.No; this.Columns[iColIdx].Bound = false; PrismGridViewCheckBoxColumn cbc = new PrismGridViewCheckBoxColumn(); // set our custom properties
cbc.HasClientCheckBoxOnClick = this.HasClientCheckBoxOnClick; cbc.ParentClientId = this.ID; cbc.ClientCheckBoxOnClick = this.ClientCheckBoxOnClick; ... this.Columns[iColIdx].CellTemplate = cbc; this.Columns[iColIdx].IsAutoWidth = false; this.Columns[iColIdx].Width = Unit.Pixel(20); this.Columns[iColIdx].CellStyle.Width = Unit.Pixel(20); this.Columns[iColIdx].CellStyle.HorizontalAlign = ISNet.WebUI.HorizontalAlign.Center; this.Columns[iColIdx].CellStyle.VerticalAlign = ISNet.WebUI.VerticalAlign.Middle;

 

The attached images show the intitial load of the grid with the default and saved db layouts as well as both after the Refresh grid data is hit.  Notice the check boxes are not there in the initial load but there after the post back.  Any help would be greatly appreciated.  Thank you.

 Please let me know if additional information is needed.  We really need to get this fixed ASAP please.

Also, as a side note and one other issue related here is if we don't call "this.RetrieveStructure();" we get JavaScript errors all over the place on post backs after we load the layout from the database.  These are internal errors to the WebGrid, e.g., "var vec863 =vad719.replace(/[&]/g,"%26");" and so on.

All times are GMT -5. The time now is 7:05 AM.
Previous Next