3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 11 Feb 2010, 07:22 AM
Hello,
I am not sure whether it is possible to change the
-Shinu.
I am not sure whether it is possible to change the
Expression of GridCalculatedColumn for each row in the grid based on cell value. One suggestion to achieve the same functionality is by adding GridTemplateColumn with Label control placed inside and setting the Text property for the label after calculating the result explicitly in ItemDataBound event.-Shinu.
0
Pierre
Top achievements
Rank 1
answered on 11 Feb 2010, 12:47 PM
Hi Shinu,
Normally i may use this feature changing runtime the columns for declarative columns but some reason i can't cast "AS"
Sample
my
error :No property or field 'as' exists in type 'DataRowView'
Thanks
Normally i may use this feature changing runtime the columns for declarative columns but some reason i can't cast "AS"
Sample
| protected void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e) |
| { |
| if(e.Column.UniqueName == "BirthDate") |
| { |
| GridBoundColumn boundColumn = e.Column as GridBoundColumn; |
| boundColumn.ReadOnly = true; |
| boundColumn.DataFormatString = "{0:d}"; |
| } |
| } |
| protected void PlanGrid_PreRender(object sender, System.EventArgs e) |
| { |
| foreach (GridColumn column in PlanGrid.Columns) |
| { |
| if (column.UniqueName == "PriceUs") |
| { |
| ((GridCalculatedColumn)column).Expression = "{0}/" + RUNTIMEVALUE; |
| break; |
| } |
| } |
| PlanGrid.Rebind(); |
| } |
error :No property or field 'as' exists in type 'DataRowView'
Thanks
0
Hello Pierre,
I am afraid the behavior you are trying to attain is not possible. However, to achieve your goal you could use the ItemDataBound event. When it is raised you can perform the required calculation and then apply the modified text to the CalculatedColumn cell:
To avoid the error with message "No property or field 'as' exists in type 'DataRowView'" you need to set the Expression property of the CalculatedColumn column:
Also you could check out the following online documentation article which explains the RadGrid's column types:
http://www.telerik.com/help/aspnet-ajax/grdcolumntypes.html
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx
I hope this helps.
Regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I am afraid the behavior you are trying to attain is not possible. However, to achieve your goal you could use the ItemDataBound event. When it is raised you can perform the required calculation and then apply the modified text to the CalculatedColumn cell:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = e.Item as GridDataItem; item["TotalCost"].Text = Convert.ToDecimal(item["minPrice"].Text) + RUNTIMEVALUE; }}To avoid the error with message "No property or field 'as' exists in type 'DataRowView'" you need to set the Expression property of the CalculatedColumn column:
<telerik:GridCalculatedColumn HeaderText="Total Cost" UniqueName="TotalCost" DataType="System.Decimal" DataFields="minPrice, maxPrice" Expression="{0}+{1}" />Also you could check out the following online documentation article which explains the RadGrid's column types:
http://www.telerik.com/help/aspnet-ajax/grdcolumntypes.html
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/calculatedcolumns/defaultcs.aspx
I hope this helps.
Regards,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
