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

Invalid column name:

2 Answers 383 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Salman
Top achievements
Rank 1
Salman asked on 12 Nov 2012, 02:02 PM
Hi all member
I have a grid in asp and add
GridColumnGroup and column in code behind.
i add in page load event before i set value for colums but when page post back to server raise error
Invalid column name:
this my code

plase help to me
thanks

protected void Page_Load(object sender, EventArgs e)
       {
           if (Page.IsPostBack == false)
           {
               txtDate.Text = clsMain.GetPersianDate();
                
               CreateStructureTable();
               fillZoneData();
               fillAreaData();
               fillPlacetype();
               if (objZone.dtblZone.Rows.Count == 0 || objArea.dtblZone.Rows.Count==0)
               {
                   string script = "Error('شما به منطقه ای مشخص دسترسی ندارید')";
                  // ScriptManager.RegisterStartupScript(this, GetType(), "MyKey", script, true);
               }
               else
               {
                   FillPlaceInTable();
                   FillDataInTable();
                     
               }
           }
       }
private void CreateStructureTable()
       {
           int i = 0;
           string s = "";
           #region "GridClear"
           dgdZone.MasterTableView.Columns.Clear();
          // dgdZone0.MasterTableView.Columns.Clear();
           dgdZone.MasterTableView.ColumnGroups.Clear();
           #endregion
           
           #region "GridColumnGroup"
           objContractItem.dtblContractItem = clsMain.SelectByCondition("Select * from vContractItem where iNumber In(Select iParentNumber from vContractItem) Order by ContractItemLevel asc");
           for (i = 0; i <= objContractItem.dtblContractItem.Rows.Count - 1; i++)
           {
               if (!dgdZone.MasterTableView.ColumnGroups.Contains(objContractItem.dtblContractItem.Rows[i]["iNumber"]))
               {
                   GridColumnGroup grp = new GridColumnGroup();
                   grp.HeaderText = objContractItem.dtblContractItem.Rows[i]["strName"].ToStr().Replace(" ", "").Replace(":", "");
                   grp.Name = "grp" + objContractItem.dtblContractItem.Rows[i]["iNumber"].ToStr().Replace(" ", "").Replace(":", "");
                   grp.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
                   grp.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                   if (objContractItem.dtblContractItem.Rows[i]["iParentNumber"].ToInt() != 0)
                   {
                       grp.ParentGroupName = "grp" + objContractItem.dtblContractItem.Rows[i]["iParentNumber"].ToStr().Replace(" ", "").Replace(":", "");
                   }
                   dgdZone.MasterTableView.ColumnGroups.Add(grp);
               }
           }
           #endregion
           //------------------------------ردیف
           Telerik.Web.UI.GridBoundColumn iRowNumber = new Telerik.Web.UI.GridBoundColumn();
           dgdZone.MasterTableView.Columns.Add(iRowNumber);
           //dgdZone0.MasterTableView.Columns.Add(iRowNumber);
           iRowNumber.HeaderText = "ردیف";
           iRowNumber.UniqueName = "iRowNumber";
           iRowNumber.DataField = "iRowNumber";
           iRowNumber.Visible = true;
           iRowNumber.HeaderStyle.Width = Unit.Pixel(40);
           iRowNumber.ItemStyle.Width = Unit.Pixel(20);
           iRowNumber.ForceExtractValue = GridForceExtractValues.Always;
           iRowNumber.AllowFiltering = false;
           iRowNumber.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
           iRowNumber.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
           iRowNumber.ItemStyle.VerticalAlign = VerticalAlign.Middle;
           iRowNumber.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
           dt.Columns.Add("iRowNumber", i.GetType());
           dt2.Columns.Add("iRowNumber", s.GetType());
           //------------------------------------------
           //------------------------شناسه محل
           Telerik.Web.UI.GridBoundColumn iZonePlaceNumberCol = new Telerik.Web.UI.GridBoundColumn();
           dgdZone.MasterTableView.Columns.Add(iZonePlaceNumberCol);
         //  dgdZone0.MasterTableView.Columns.Add(iZonePlaceNumberCol);
           iZonePlaceNumberCol.HeaderText = "iZonePlaceNumber";
           iZonePlaceNumberCol.UniqueName = "iZonePlaceNumber";
           iZonePlaceNumberCol.DataField = "iZonePlaceNumber";
           iZonePlaceNumberCol.Visible = false;
           iZonePlaceNumberCol.ForceExtractValue = GridForceExtractValues.Always;
           dt.Columns.Add("iZonePlaceNumber", i.GetType());
           dt.Columns.Add("strPlaceName", s.GetType());
           //------------------------------
           //--------------------------------نام محل
          
           Telerik.Web.UI.GridBoundColumn strPlaceNameCol = new Telerik.Web.UI.GridBoundColumn();
           dgdZone.MasterTableView.Columns.Add(strPlaceNameCol);
         //  dgdZone0.MasterTableView.Columns.Add(strPlaceNameCol);
           strPlaceNameCol.HeaderText = "نام محل";
           strPlaceNameCol.UniqueName = "strPlaceName";
           strPlaceNameCol.DataField = "strPlaceName";
           strPlaceNameCol.Visible = true;
           strPlaceNameCol.HeaderStyle.Width = Unit.Pixel(180);
           strPlaceNameCol.ItemStyle.Width = Unit.Pixel(180);
           strPlaceNameCol.ForceExtractValue = GridForceExtractValues.Always;
           strPlaceNameCol.AllowFiltering = false;
           strPlaceNameCol.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
           strPlaceNameCol.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
           strPlaceNameCol.ItemStyle.VerticalAlign = VerticalAlign.Middle;
           strPlaceNameCol.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
           strPlaceNameCol.AllowSorting = false;
           strPlaceNameCol.AllowFiltering = false;
           dt2.Columns.Add("iZonePlaceNumber", i.GetType());
           dt2.Columns.Add("strPlaceName", s.GetType());
           //------------------------------
            
            
           objContractItem.dtblContractItem = clsMain.SelectByCondition("Select * from vContractItem where bShowDailyReport=1" + " Order by iParentNumber asc");
           for (i = 0; i <= objContractItem.dtblContractItem.Rows.Count - 1; i++)
           {
               Telerik.Web.UI.GridBoundColumn col = new Telerik.Web.UI.GridBoundColumn();
               if (objContractItem.dtblContractItem.Rows[i]["bIncomplete"].ToBool() == true)
               {
                 //  dgdZone0.MasterTableView.Columns.Add(col);
                   dt2.Columns.Add(objContractItem.dtblContractItem.Rows[i]["iNumber"].ToString(), i.GetType());
               }
               else
               {
                   dgdZone.MasterTableView.Columns.Add(col);
                   dt.Columns.Add(objContractItem.dtblContractItem.Rows[i]["iNumber"].ToString(), i.GetType());
               }
               if (objContractItem.dtblContractItem.Rows[i]["iParentNumber"].ToStr().Length > 0)
               {
                   //col.ColumnGroupName = "grp" + objContractItem.dtblContractItem.Rows[i]["iParentNumber"].ToStr();
               }
               col.UniqueName =objContractItem.dtblContractItem.Rows[i]["iNumber"].ToString();
               col.DataField = objContractItem.dtblContractItem.Rows[i]["iNumber"].ToString();
               col.ForceExtractValue = GridForceExtractValues.Always;
               col.HeaderText = objContractItem.dtblContractItem.Rows[i]["strName"].ToString();
               col.HeaderStyle.VerticalAlign = VerticalAlign.Middle;
               col.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
               col.ItemStyle.VerticalAlign = VerticalAlign.Middle;
               col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
               col.HeaderStyle.Width = Unit.Pixel(100);
               col.AllowSorting = false;
               col.AllowFiltering = false;
               col.Groupable = false;
           }
           // }
           GlobalMActivity.dt = dt;
           GlobalMActivity.dt2 = dt2;
           dgdZone.DataSource = dt;
           //dgdZone0.DataSource = dt2;
           dgdZone.DataBind();
        //   dgdZone0.DataBind();
       }

2 Answers, 1 is accepted

Sort by
0
Salman
Top achievements
Rank 1
answered on 13 Nov 2012, 11:28 AM
please help to me
0
Eyup
Telerik team
answered on 15 Nov 2012, 07:42 AM
Hi Salman,

This error indicates that you are adding the column groups incorrectly. Please check out the following thread for the appropriate approach:
http://www.telerik.com/community/forums/aspnet-ajax/grid/export-with-dynamic-headergroup.aspx

I hope this will prove helpful.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Salman
Top achievements
Rank 1
Answers by
Salman
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or