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

Multi-header generating on server side

1 Answer 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maxime
Top achievements
Rank 1
Maxime asked on 04 Jul 2012, 08:58 AM
Hi everyone !

I am currently working with grid, generated on server-side depending on a parameter, with multi-header function.

Here is my code and some explanations :

- First part : Generating the first headergroup column. It contains my labels.
- Second part (first "for" loop) : Generate all my column headers
- Third part (second "for" loop) : Generate the databoundcolumns. I will bind data with it.

    //Indices
    int i_incrementA = 0,
        i_incrementB = 0;
 
    // Return the number of molds we are working for with the samples
    int i_gridLines = l_resMou[0].OBJ_RESULTAT.OBJ_PRELEV.LST_MOULE.Count();
    // Return the number of controls we are working on.
    int i_gridColumns = l_resMou[0].OBJ_RESULTAT.OBJ_PRELEV.LST_RESULTAT.Count();
 
    long i_currentResult = 0;
    long i_currentMold = 0;
 
    GridColumnGroup GCG_headerGroup = new GridColumnGroup();
    GridBoundColumn GCO_columns = new GridBoundColumn();
 
    // Add the first column wich will content mold numbers.
    // First header row : Controls
    GCG_headerGroup.Name = "control0";
    GCG_headerGroup.HeaderText = "";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    //Second header row : Buttons
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "buttons0";
    GCG_headerGroup.HeaderText = "";
    GCG_headerGroup.ParentGroupName = "control0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    // Third header row : Max
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "max0";
    GCG_headerGroup.HeaderText = "Max :";
    GCG_headerGroup.ParentGroupName = "buttons0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    // Fourth header row : MaxWarn
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "maxWarn0";
    GCG_headerGroup.HeaderText = "Warn :";
    GCG_headerGroup.ParentGroupName = "max0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    // Fifth header row : Target
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "target0";
    GCG_headerGroup.HeaderText = "Target :";
    GCG_headerGroup.ParentGroupName = "maxWarn0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    // Sixth header row : MinWarn
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "minWarn0";
    GCG_headerGroup.HeaderText = "Warn :";
    GCG_headerGroup.ParentGroupName = "target0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    // Seventh header row : Min
    GCG_headerGroup = new GridColumnGroup();
    GCG_headerGroup.Name = "min0";
    GCG_headerGroup.HeaderText = "Min :";
    GCG_headerGroup.ParentGroupName = "minWarn0";
    GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
 
    for (i_incrementB = 0; i_incrementB < i_gridColumns; i_incrementB++)
    {
        i_currentResult = l_resMou[0].OBJ_RESULTAT.OBJ_PRELEV.LST_RESULTAT[i_incrementB].RECLEUNIK;
        i_currentMold = l_resMou[0].OBJ_RESULTAT.OBJ_PRELEV.LST_MOULE[i_incrementB].MOCLEUNIK;
             
        // Create a headerGroup for the control name.
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "control" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = l_resMou.Where(r => r.OBJ_RESULTAT.RECLEUNIK == i_currentResult & r.OBJ_MOULE.MOCLEUNIK == i_currentMold).Single<EntityRESMOU>().OBJ_RESULTAT.OBJ_TOLERANCES.OBJ_CONTROLE.OBJ_TYPECTRL.NOMTYPE;
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // buttons header groups
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "buttons" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "control" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "buttons";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // Tolerances Max
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "max" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "buttons" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // Tolerances MaxWarn
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "maxWarn" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "max" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // Tolerances Target
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "target" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "maxWarn" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // Tolerances MinWarn
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "minWarn" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "target" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
        // Tolerances Target
        GCG_headerGroup = new GridColumnGroup();
        GCG_headerGroup.Name = "min" + (i_incrementB + 1);
        GCG_headerGroup.ParentGroupName = "minWarn" + (i_incrementB + 1);
        GCG_headerGroup.HeaderText = "";
        GRD_CONTROLLIST.MasterTableView.ColumnGroups.Add(GCG_headerGroup);
    }
 
    // Data fields
    // WARNING : Be careful of the column name which must be the same as the datasource column name.
    for (i_incrementB=0;i_incrementB<i_gridColumns+1;i_incrementB++)
    {
        GCO_columns = new GridBoundColumn();
        GCO_columns.ColumnGroupName = "min" + i_incrementB;
        GCO_columns.UniqueName = "col" + i_incrementB;
        GCO_columns.DataField = "col" + i_incrementB;
        GCO_columns.HeaderText = "col" + i_incrementB;
        GRD_CONTROLLIST.MasterTableView.Columns.Add(GCO_columns);
    }
 
}

my headergroups are correctly generated.
So, i do my databinding with static data from a DataTable :

DataTable TBL_setOutResults = new DataTable();
for (int i = 0; i < 9; i++)
{
    TBL_setOutResults.Columns.Add("col"+i);
}
 
TBL_setOutResults.Rows.Add("#6", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#12", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#16", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#17", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#20", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#24", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#32", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#33", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#34", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#36", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#41", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#47", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#52", "10", "10", "10", "10", "10", "10", "10", "10");
TBL_setOutResults.Rows.Add("#55", "10", "10", "10", "10", "10", "10", "10", "10");
 
GRD_CONTROLLIST.DataSource = TBL_setOutResults;
GRD_CONTROLLIST.DataBind();

DataTable column names are the same than databoundcolumn inside my grid.
But there is a problem. See the first attachement : "grid.jpg". The binding seems to be done 2 times.
In fact, i just want to remove the right part of the generated grid. ( the big columns col0, col1, col2 .. etc ...à).

So, i checked the HTML code and it seems that my datatable columns generate a columngroup on the same level that my first columngroup. See  the second attachement : "htmlcode.jpg"

Am i doing it wrong ? Is there a solution ?
Many thanks for your help !

  • ASP.NET version: 4.0
  • OS: WS2008R2
  • exact browser version: Firefox 13.0
  • exact version of the Telerik product : RadControls for ASP.NET AJAX Q2 2012
  • preferred programming language : C#

1 Answer, 1 is accepted

Sort by
0
Maxime
Top achievements
Rank 1
answered on 04 Jul 2012, 12:00 PM
Hi,

In fact, Radgrid still generated columns on runtime ... My bad :/
I just had to disable this function.
Tags
Grid
Asked by
Maxime
Top achievements
Rank 1
Answers by
Maxime
Top achievements
Rank 1
Share this question
or