I have created a custom control to implement a grid we use all over the place. It has been working fine for a while and now I was asked to add a new column type that would allow any valid asp.net markup to be put in it and that markup will be rendred within that table column.

I created the following class:

    [PersistChildren(false), ParseChildren(true)]
    public class UserDefinedMarkupColumn : GridColumnBase
        private Collection<WebControl> _innerMarkup = new Collection<WebControl>();

        public virtual Collection<WebControl> InnerMarkup { get { return _innerMarkup; } }

        public override System.Web.UI.WebControls.TableCell CreateCell(object dataSourceObject, GridColumnBase col, out CustomGridRow extraRow, Action<object, System.Web.UI.WebControls.CommandEventArgs> handler, bool isMobileLayout = false)
            TableCell newCell = new TableCell();

            foreach (var ctrl in _innerMarkup)

            extraRow = null;
            return newCell;

and this markup for the column:

<CustomGrid:UserDefinedMarkupColumn ID="markup" HeaderText="Some Markup">
      <asp:TextBox runat="server" />

The problem is that when I hit CreateCell the _innerMarkup collection is always empty. I saw several samples using a ControlsCollection but the issue is that GridColumnBase does not inherit from Control, it creates a TableCell which does.

Related posts

Recent Viewed