Adding Column Groups Dynamically giving "Invalid Column" error.

5 posts, 0 answers
  1. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 24 Sep 2014 Link to this post


    I am using advanced binding and creating dynamic columns during Page_Init event.
    Everything works fine except column groups.

    I am creating column groups based on my data and then linking them to columns eventually in page_init event.

    Below is the code I am trying to use. Everything is fine on first load. When we try to refresh grid, nothing works. I am getting "Invalid Column Name" error.


                DataSet dsSubmittals = new DataSet();
                DataSet dsCycles = new DataSet();
                string SubID = Session["SubmitalID"].ToString();
                if (Session["SubmitalID"] != null)
                {
                    dsCycles = _dv.GetProjectCycles(ProjectID);
                    //for (int k = 0; k < dsCycles.Tables[0].Rows.Count; k++)
                    //{
                    //    GridColumnGroup CycleGroup = new GridColumnGroup();
                    //    CycleGroup.HeaderText = dsCycles.Tables[0].Rows[k]["CycleName"].ToString();
                    //    CycleGroup.Name = dsCycles.Tables[0].Rows[k]["CycleID"].ToString();
                    //    RadGridResults.MasterTableView.ColumnGroups.Add(CycleGroup);

                    //}

                    //GridColumnGroup CycleGroup1 = new GridColumnGroup();
                    //CycleGroup1.HeaderText = "Final Status";
                    //CycleGroup1.Name = "Final_Status";
                    //RadGridResults.MasterTableView.ColumnGroups.Add(CycleGroup1);

                    int index = 4;
                    if (dsCycles.Tables[0].Rows.Count > 1)
                    {
                        for (int j =1;j< dsCycles.Tables[0].Rows.Count; j++)
                        {

                            string colName = dsCycles.Tables[0].Rows[dsCycles.Tables[0].Rows.Count-j]["CycleName"].ToString();
                            string CycleIdValue = dsCycles.Tables[0].Rows[dsCycles.Tables[0].Rows.Count-j]["CycleID"].ToString();
                            colName = colName.Replace(" ", string.Empty);
                            bool chk = false;
                            for (int k = 0; k < RadGridResults.Columns.Count; k++)
                            {
                                if (RadGridResults.Columns[k].UniqueName != string.Empty)
                                    if (RadGridResults.Columns[k].UniqueName == colName)
                                    {
                                        RadGridResults.Columns[k].HeaderText = RadGridResults.Columns[k].UniqueName;
                                        chk = true;
                                        break;
                                    }
                            }
                            if (!chk)
                            {
                                int loc = index + j;
                                GridBoundColumn bf = new GridBoundColumn();
                                bf.DataField = colName.Trim();
                                bf.HeaderStyle.Width = 55;
                                bf.FilterControlWidth = 22;
                                bf.UniqueName = colName.Trim();
                                bf.HeaderText = colName.Trim();
                                bf.HeaderText = colName.Trim();
                                bf.SortExpression = colName;
                                bf.FooterText = CycleIdValue;
                                bf.HeaderButtonType = GridHeaderButtonType.TextButton;
                               // bf.ColumnGroupName = "Final_Status";
                                RadGridResults.MasterTableView.Columns.AddAt(loc, bf);

                               

                            }
                        }
                    }


    Thanks,
    Anil
  2. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 26 Sep 2014 in reply to Anil Link to this post

    any suggestions !!!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 Sep 2014 Link to this post

    Hi,

    From the code provided I did not notice anything that can cause this behavior. Could you please send us a stripped down version of the project or at least the markup and code-behind of the problematic page so we could investigate further? Once we have a sample which we can inspect locally we should be able to quickly resolve the problem.

    Hope to hear from you soon.


    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Anil
    Anil avatar
    8 posts
    Member since:
    Jun 2013

    Posted 02 Oct 2014 in reply to Pavlina Link to this post

    We have some static columns and in Page_init I am adding more columns to it and assigning column groups to dynamically added columns. Can we have static and dynamic columns and still be able to use column groups? If not, any work around for this?
  6. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Oct 2014 Link to this post

    Hello,

    ​The problem might be related to the mixing of static and dynamic columns. Could you try to create all columns dynamically on Page_Init? You should follow the programmatic creation article and add the column groups and columns to the Columns collection of MasterTableView after their attributes are set.

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017