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

Dynamically change GridColumnGroup text

3 Answers 738 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GDPR_erased
Top achievements
Rank 1
GDPR_erased asked on 15 Feb 2014, 02:39 PM
I have a simple radgrid that has one GridColumnGroup that displays above 4 bound columns.
------------------------------
<ColumnGroups>
<telerik:GridColumnGroup HeaderText="Reporting Period" Name="ReportingPeriod"/>
</ColumnGroups>

<telerik:GridBoundColumn DataField="Numerator" HeaderText="Numerator" UniqueName="Numerator"  ColumnGroupName="ReportingPeriod" />

That is all, there is no "grouping", etc. It is purely for display.

Is there a way to  change the HeaderText of the GridColumnGroup dynamically? I cannot seem to be able to access it on itemdatabound, or any other way. I want to change the text to a "value", but there is no way to reference it? (to the reporting period dates dynamically)
Any help would be appreciated.
Thanks


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Feb 2014, 04:09 AM
Hi Bill,

Please try the following code snippet to set the GridColumnGroup HeaderText :

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 RadGrid1.MasterTableView.ColumnGroups[0].HeaderText = "Header Text";
}

Thanks,
Princy
0
GDPR_erased
Top achievements
Rank 1
answered on 17 Feb 2014, 12:49 PM
Thanks for the information. I had tried that before on the itemdatabound (which is where I need it):

grdReadiness.MasterTableView.ColumnGroups.FindGroupByName("ReportingPeriod").HeaderText = ""

And, it finds the groupheader just fine (stepping thru it), but here is the problem.. The page come up, but the groupcolumn header text is not changed!! Now, as soon as I click on a column to sort, (or page) it changes!
It is like it is not there the first time on the page initial load.
Thanks for the help.
0
Princy
Top achievements
Rank 2
answered on 18 Feb 2014, 03:16 AM
Hi Bill,

You can try to set the Text in the PreRender event as follows:

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 RadGrid1.MasterTableView.ColumnGroups.FindGroupByName("ReportingPeriod").HeaderText = "";
 RadGrid1.Rebind();
}

When using ItemDataBound event also, I was able to get it to work. Can you provide your code snippet so as to help you with the requirement.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 RadGrid1.MasterTableView.ColumnGroups.FindGroupByName("ReportingPeriod").HeaderText = "";   
}

Thanks,
Princy
Tags
Grid
Asked by
GDPR_erased
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
GDPR_erased
Top achievements
Rank 1
Share this question
or