This is a migrated thread and some comments may be shown as answers.

Adding Column Groups Dynamically giving "Invalid Column" error.

4 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anil
Top achievements
Rank 1
Anil asked on 25 Sep 2014, 04:30 AM

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

4 Answers, 1 is accepted

Sort by
0
Anil
Top achievements
Rank 1
answered on 26 Sep 2014, 08:17 PM
any suggestions !!!
0
Pavlina
Telerik team
answered on 30 Sep 2014, 07:46 AM
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.

 
0
Anil
Top achievements
Rank 1
answered on 02 Oct 2014, 10:49 PM
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?
0
Pavlina
Telerik team
answered on 08 Oct 2014, 09:10 AM
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.

 
Tags
Grid
Asked by
Anil
Top achievements
Rank 1
Answers by
Anil
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or