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

Set a column's headertext equal to a value from a row in the grid's datasource?

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 04 Nov 2011, 08:21 PM
How do you set the a column's headertext equal to a value from a row in the grid's datasource? Any row is fine, because the column I want the data from has the same value in every single row that gets returned. i.e. Here are some columns in the sqldatasource:
Employee  R1_Assigned  R1_ClientName  R2_Assigned  R2_ClientName ...
Dave      Yes          ABC Foods       No          Coca Cola  
Bill      No           ABC Foods       Yes         Coca Cola  
John      Yes          ABC Foods       No          Coca Cola

My sqldatasource returns a variable number of columns, usually around 50-60 or so clients. So I build them dynamically and might have R50_ClientName for example. It's kind of like a cross tab query. Employees are each row. The varaible # of columns represent active clients and whether or not that employee works for that client. So I want the header of those 50 columns to be the real name of the client. "ABC Foods" is the text I want which is in column R1_ClientName, I do not want "R1_Assigned" which is the name of the data field that the column is bound to. Here is how I build them:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GridBoundColumn boundColumn;
        boundColumn = new GridBoundColumn();
        this.RadGrid1.MasterTableView.Columns.Add(boundColumn);               
        boundColumn.DataField = "R1_Assigned";
        boundColumn.HeaderText = ??? // I want to set this equal to value from column: R1_ClientName


1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Nov 2011, 06:20 AM
Hello,

void RadGrid1_PreRender(object sender, EventArgs e)
    {
         
 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            // do your logic if you want
        }
 
        foreach (GridHeaderItem chitem in RadGrid1.MasterTableView.GetItems(GridItemType.Header))
        {
            chitem["ColumnUbiqueName1"].Text = "My Header";
            chitem["ColumnUbiqueName2"].Text = RadGrid1.MasterTableView.Items.Count.ToString();
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or