Dynamically generated columns in radgrid disappear after postback

4 posts, 0 answers
  1. nader
    nader avatar
    18 posts
    Member since:
    Nov 2010

    Posted 30 Apr 2015 Link to this post

    Am using radgrid and creating it in aspx but on certain action i add more GridTemplateColumns to the grid.

        private void CreateDateColumns(List<DateTime> occurenceList)
            if (occurenceList != null && occurenceList.Count > 0)
                int index = 1;
                foreach (DateTime occurence in occurenceList)
                    string templateColumnName = occurence.Date.ToShortDateString();
                    GridTemplateColumn templateColumn = new GridTemplateColumn();
                    templateColumn.ItemTemplate = new MyTemplate(templateColumnName, index);
                    templateColumn.HeaderText = templateColumnName;
                    templateColumn.UniqueName = templateColumnName;

        private class MyTemplate : ITemplate
            protected RadComboBox rcbAttendance;
            private string colname;
            private int _index;
            public MyTemplate(string cName, int index)
                colname = cName;
                _index = index;
            public void InstantiateIn(System.Web.UI.Control container)
                rcbAttendance = new RadComboBox();
                rcbAttendance.Items.Add(new RadComboBoxItem("---Select---", "-1"));
                rcbAttendance.Items.Add(new RadComboBoxItem("Present", "1"));
                rcbAttendance.Items.Add(new RadComboBoxItem("Absent", "2"));
                rcbAttendance.Items.Add(new RadComboBoxItem("Leave", "3"));
                rcbAttendance.ID = "rcbAttendance" + _index;

    All are fine with creation but when i press save button or any combobox make postback the only dynamically generated columns content disappear and the other columns stay.
    What i noticed that columns still in place with headertext but only content are disappeared (in my case content are comboboxes)

    After enabling viewstate for grid only header text appear.

    What should i do to keep columns contents after postback and get their values ?
  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 05 May 2015 Link to this post

    Hi Nader,

    If your RadGrid structure will be changed dynamically, you need to follow the exact steps listed in the following help article:
    As you will notice, you need to ensure that the columns are added within the Page's Load event handler and that the EnableColumnsViewState property of the MasterTableView is set to false

    Hope this helps.

    Konstantin Dikov

    See What's Next in App Development. Register for TelerikNEXT.

  3. nader
    nader avatar
    18 posts
    Member since:
    Nov 2010

    Posted 05 May 2015 in reply to Konstantin Dikov Link to this post

    Hi Konstantin ,

     I solved this issue already with something near what u mentioned, i have to draw the columns every post-back with saving values in each call. Anyway thanks for help

  4. Swati
    Swati avatar
    7 posts
    Member since:
    Jan 2017

    Posted 21 Jul 2017 in reply to nader Link to this post


    Can u please share complete solution or with exact code what you have done.  It will be great help.


    Thank you in advance.



Back to Top