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

Header Lost

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahmed Ilyas
Top achievements
Rank 1
Ahmed Ilyas asked on 02 Feb 2013, 12:44 AM
I am programmatically adding columns to the RadGrid.
The problem is, after a postback (when say expanding the grid even though there is no code to populate data for the next level down hierarchy), the heading columns are gone.

any ideas why?

I also need to state that, should there be a postback from a column, which will be added in the future, that I need to obtain the modified row column values also.

protected void Page_Load(object sender, EventArgs e)
        {
            this.DoSetDefaultMenuColumns();
        }
 
        private void DoSetDefaultMenuColumns()
        {
            // lets create the columns.
            GridBoundColumn menuIDColumn = new GridBoundColumn();
            menuIDColumn.HeaderText = "Menu ID";
            menuIDColumn.DataField = "MenuID";
 
            GridBoundColumn menuNameColumn = new GridBoundColumn();
            menuNameColumn.HeaderText = "Menu Name";
            menuNameColumn.DataField = "MenuName";
 
            GridDropDownColumn menuOrderColumn = new GridDropDownColumn();
            menuOrderColumn.HeaderText = "Menu Order ID";
            menuOrderColumn.DataField = "MenuOrderID";
 
            GridDropDownColumn parentIDColumn = new GridDropDownColumn();
            parentIDColumn.HeaderText = "Parent ID";
            parentIDColumn.DataField = "ParentID";
 
            GridCheckBoxColumn isAdminColumn = new GridCheckBoxColumn();
            isAdminColumn.HeaderText = "Is Admin";
            isAdminColumn.DataField = "IsAdmin";
 
            GridBoundColumn pageURLColumn = new GridBoundColumn();
            pageURLColumn.HeaderText = "Page URL";
            pageURLColumn.DataField = "PageURL";
 
            GridCheckBoxColumn employeeAccessColumn = new GridCheckBoxColumn();
            employeeAccessColumn.HeaderText = "Employee Access";
            employeeAccessColumn.DataField = "EmployeeAccess";
 
            GridCheckBoxColumn customerAccessColumn = new GridCheckBoxColumn();
            customerAccessColumn.HeaderText = "Customer Access";
            customerAccessColumn.DataField = "CustomerAccess";
 
            this.radGridMenus.MasterTableView.Columns.Add(menuIDColumn);
            this.radGridMenus.MasterTableView.Columns.Add(menuNameColumn);
            this.radGridMenus.MasterTableView.Columns.Add(menuOrderColumn);
            this.radGridMenus.MasterTableView.Columns.Add(parentIDColumn);
            this.radGridMenus.MasterTableView.Columns.Add(pageURLColumn);
            this.radGridMenus.MasterTableView.Columns.Add(isAdminColumn);
            this.radGridMenus.MasterTableView.Columns.Add(employeeAccessColumn);
            this.radGridMenus.MasterTableView.Columns.Add(customerAccessColumn);
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2013, 05:08 AM
Hi,

Try defining the grid in Page_Init event as shown below.
C#:
protected void Page_Init(object sender, EventArgs e)
   {
       this.DoSetDefaultMenuColumns();
   }

Thanks,
Shinu
0
Ahmed Ilyas
Top achievements
Rank 1
answered on 04 Feb 2013, 10:44 AM
I tried this but it did not quite work. it seemed to have doubled the header columns on every postback.
0
Pavlina
Telerik team
answered on 04 Feb 2013, 04:45 PM
Hello Ahmed,

To resolve the problem with duplicate columns you should set the EnableColumnViewState property to False, so that the grid knows that the columns may vary at some stage of the page lifecycle. I also recommend you read the article below which elaborates on changing grid structure dynamically:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

Greetings,
Pavlina
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
Ahmed Ilyas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ahmed Ilyas
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or