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

Change headertext from detailtable in dynamically programmed grid

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tosj
Top achievements
Rank 1
Tosj asked on 14 Jul 2011, 07:58 AM
I'm having a problem with changing the headertext in my detailtable..
I'm creating multiple grids by a loop and show the underneath eachother..
Because the columns in my detailtable are variable, I didn't bound them..

So is there a way to change the headertext?

RadGrid[] GridName = new RadGrid[intTotalProcessTemplates];
  
        
            for (int i = 0; i < intTotalProcessTemplates; ++i)
            {
                // Create mastertable
                GridName[i] = new RadGrid();
                GridName[i].DataSource = GetDataTable("SELECT * FROM ProcessTemplate WHERE ProcessTemplate_id = " + (i + 1));
                GridName[i].MasterTableView.DataKeyNames = new string[] { "ProcessTemplate_id" };
                GridName[i].Skin = "Black";
                GridName[i].AutoGenerateColumns = false;
                GridName[i].AllowPaging = true;
  
                // Columns create
                GridName[i].MasterTableView.Columns.Add(CreateGridColumn("Process name", "Name", 10.0));
                GridName[i].MasterTableView.Columns.Add(CreateGridColumn("Process description", "Description", 80.0));
                GridName[i].MasterTableView.Columns.Add(CreateGridColumn("Parent", "Parent", 10.0));
  
                // Create detail table
                GridTableView tableViewStartProcesses = new GridTableView(GridName[i]);
                tableViewStartProcesses.DataKeyNames = new string[] { "Process_id" };
                tableViewStartProcesses.AutoGenerateColumns = true;
                tableViewStartProcesses.AllowPaging = true;
                tableViewStartProcesses.CommandItemDisplay = GridCommandItemDisplay.Top;
  
                foreach (GridColumn col in tableViewStartProcesses.RenderColumn)
                {
                    if (col.UniqueName == "templateid")
                    {
                        col.HeaderText = "Template id";
                    }
                }
  
                // Fix result from stored proc: GetAllProcessesAndSteps_SP
                LinqResult(tableViewStartProcesses, i);
  
                // Add Details to table
                GridName[i].MasterTableView.DetailTables.Add(tableViewStartProcesses);;
  
                // Add to placeholder
                this.StartProcessPlaceHolder.Controls.Add(GridName[i]);

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Jul 2011, 10:01 AM
Hello Tosj,

It is not possible to set the header text for the autogenerated columns before they are actually created. You have to use event like ItemCreated/ItemDataBound/PreRender or similar.

Regards,
Daniel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Tosj
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or