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
20
Dynamically Created TemplatedColumn and Paging
posted

I'm using an Ultrawebgrid and dynamically creating columns at runtime (in the code behind).  Most of the columns are just UltraGridColumns, but a couple of them are TemplatedColumns.  The cells contain arrays of objects that are iterated within the template.  When the grid first loads, it works flawlessly.  However, when I move to a different page of the table, the Templating suddenly disappears and I just see the classname of the arrays.  When debugging, the ColumnCollection on the grid is loading the columns as plain UltraGridColumns.

The contents of the cells and the templates are serializable.

Anyone have any idea why the Grid would be discarding the TemplatedColumns and replacing them with UltraGridColumns?

Parents
No Data
Reply
  • 37874
    posted

    Hi soward,

    It has been some time since your post but in case that you still need assistance I will be happy to help.

    Dynamically generated columns need to be reinstantiated on every postback in the PreInit stage in order to reinitialize the templated controls (or the Init stage if using the content page of a master page). That's why in your scenario the controls do not appear. I suggest that you use separate class for the template and override the page’s preInit event to create the templated columns:

    public class templatedLabel : ITemplate

    {

        public void InstantiateIn(Control container)

        {

            Label label1 = new Label();

            label1.ID = "lbl1";

            label1.Text = "Some text";

            container.Controls.Add(label1);

        }

    }

     

    protected override void OnPreInit(EventArgs e)

    {

         base.OnPreInit(e);

         TemplatedColumn tempCol = new TemplatedColumn();

         tempCol.CellTemplate = new templatedLabel();

         tempCol.Key = "tempCol";

         UltraWebGrid1.Columns.Add("tempCol");

    }

     

    Please let me know if you have any further questions.

Children
No Data