I am using a RadGrid (Q1 2009) to edit a column of "percentages" and I am not getting the behaviour I would expect - though my expectation may be wrong.
The values stored in the database are "factors" i.e. 0.015 (for a number which the user should "see" as 1.5%), and, if I set the DataFormatString to be {0:p4} my values are displayed as expected (they are multiplied by 100 and displayed to 4 decimal places).
I would like the user to edit the values in the same way i.e. they edit/enter 12.5600% and what gets written to the database is 0.125600 and what is then re-displayed is 12.5600 %. But leaving the NumericType as "Number" ignores the DataFormatString (the value is displayed as 0.1256), and setting the NumericType to "percent" just results in a % sign being appended to the unmultiplied number (so they have to edit it as 0.125600%) which is frankly wrong.
It seems a little odd to me - is this intentional (by design), is there anything I can do to easily fix it?
37 Answers, 1 is accepted
This issue has already been reported to us. We will think about a way to improve this behavior in the future.
In the meantime, you can use the following workaround:
1. When displaying the edit form, you can modify the value, which is retrieved from the database (e.g. multiply it by 100) in the RadGrid ItemDataBound event.
2. When the edit form is submitted, there are two scenarios:
2a) If you are using RadGrid automatic operations, you have to subscribe to the Updating event of the datasource control and modify the submitted percentage value (divide it by 100).
2b) Otherwise, you have to use the RadGrid OnUpdateCommand and OnInsertCommand events to modify the submitted percentage values before updating the database.
All the best,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

Thanks for the reply, and yes your solution would work, but again this means that I have to fiddle about in code behind for all such cases.
In the end it is easier (in this one) to leave the edit as a number (factor), and just display as a percentage on the grid, I am sure the users can get used to this. Then I can wait for a fix.
If it helps, the ideal fix would be that the editor picks up the Format that has been selected "{0:p4}" and behaves accordingly - i.e. it multiplies by 100, appends a % sign, limits the number fo decimal places to 2 (i.e. 4 when dispalyed divided by 100) and so on. There will need to be a way of overriding this behaviour when the developer wants to allow the user to do something different (e.g. possibly the user is allowed to enter more than 2 (4) decimal places), but in general the format used for display shoudl be the default for editing.
Thank you for sharing your opinion. You are right that the Grid should be able to display a percentage number (0 < number < 1) in the same fashion in view and edit mode, so we will develop this behavior for a future version.
Best wishes,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

Dim tBC As New GridBoundColumn
tBC.DataFormatString = "{0:N2} %"
I am afraid this feature has not been implemented yet. It is in our to-do list, but currently we are working on taks with higher priority.
Greetings,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.

The feature has not been implemented yet. I have logged it in our public issue tracking system, so that you will be able to track any progress. The PITS item ID is 1038.
http://www.telerik.com/support/pits.aspx
Greetings,
Dimo
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 reported this over a year and ahalf ago..
the last reponse
"Posted on on May 27, 2009 CC:
Thanks for the feedback, you have raised an interesting point. We will think about it.
I have updated your Telerik points.
Greetings,
Dimo
the Telerik team "
The above, simply demonstrates that basic bugs ( this is realy not a feature request, but complience with the dotnet framework) simply does not get done, they seem to want to develop more "new products" rather than fix existing ones..
Hence, dont hold your breath for a solution.. PITS is simply a nother way of saying we dont want to do anything, so stop asking us to fix bugs..
Ray

Any updates on this issue?
Thanks
Miguel
We did further research on the issue and I am afraid that we could not change this behaviour.
You could the workaround discussed before in the second post.
The limitation comes from the fact that DataFormatString could be something that is not suitable for showing in the edit form and not reversible. For example like:
DataFormatString="{0:imaginary unit 000 myDecimalSeparator 00 }"
imaginary unit 334 myDecimalSeparator 12
You probably expect this to work for percents, as they are something common and used daily. However we can't add an exception for the percents, because this will breaks all currently working applications that expects this behaviour.
All the best,
Vasil
the Telerik team

" I am afraid that we could not change this behaviour"
This is a joke right?
Simply implement the work around, or do what 100% of other dot net controls do..
I.e implement the dotnet framework, all percentages MUST be 0 ->1 this is how the dotnet framework works, dont make up something which breaks the framework.
The stuff below is simply waffle..
In the framework itself 0.4 does not mean 40 percents when parsing. The developer who manages the data should know if it works in percents or not. For example the constructor of Unit (which is part of the framework) will not multiply the value, and it will use it as it is in original state:
Unit u1 = Unit.Percentage(75);
string
u1AsString = u1.ToString();
//u1AsString will be "75%"
double
u1AsDouble = u1.Value;
// the value will be "75.0"
Unit u2 = Unit.Percentage(0.4);
string
u2AsString = u2.ToString();
//u1AsString will be "0.4%"
double
u2AasDouble = u2.Value;
// the value will be 0.4
Best wishes,
Vasil
the Telerik team

I see the problem..
In the framewerk ( see andrews orignal request).. percentages are ALWAYS AND ONLY 0->1..
If you cannot see this than itelerick will never get a solution that works within dotnet..
Unit has absolutely nothing to do with the issue at hand..
Just fix the problem, same as 100% of any dotnet controls.. telerik si the only control provider which seems unable to make a simple percentage work in their own grid..
Let me clarify what options you have for representing your percentages in RadGrid:
1. Specifying DataFormatString in your GridNumericColumn settings:
DataFormatString="{0:p2}"
This property is only used when formatting the visible values in read-only cells. A database value of 0.52 will be displayed as 52.00% in the non-editable cells of the numeric column. The property does not affect the RadNumericTextBox instance rendered in the edited items.
2. Specifying NumericType in your GridNumericColumn settings:
NumericType="Percent"
This property affects only the numeric textbox in the edit form when you specify Percent. Using this setting, RadNumericTextBox will show a percent sign in the numeric field without modifying the original value. A database value of 0.52 will display as 0.52 % if you have specified NumericType="Percent", and will stay as 0.52 if you use the default value (NumericType="Number").
3. Implement a custom column that will take care of the percent conversion and will allow your users to enter a value between 0 and 100. When extracting the value from the column, the former will be returned as a floating point value between 0 and 1. This is easier than you might think. We need to subclass GridNumericColumn to set a few required settings, and then subclass GridNumericColumnEditor to setup the numeric textbox correctly. The complete source code of this custom percent column is attached. Including it in your grid is very easy. First register your namespace:
<%@ Register Namespace="GridCustomColumns" TagPrefix="grid" %>
And then use your percent column just like any other column:
<
telerik:RadGrid
>
<
MasterTableView
>
<
Columns
>
<
grid:GridPercentColumn
>
</
grid:GridPercentColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
The result is a percent column that displays values from 0 to 1 as integers from 0 to 100 and also allows users to enter values from 0 to 100 keeping the conversion transparent.
Veli
the Telerik team

"RadNumericTextBox will show a percent sign in the numeric field without modifying the original value. A database value of 0.52 will display as 0.52 % if you have specified NumericType="Percent",
Good description of the issue and defect..
In order to amke any grid work, one need to sue the framework 0->1 stanadrd..
If one uses your percentage control within Your grid, one gets the wrong displayed value as you demonstate above.
FULL STOP..
Been over a year and no progress on this basic defect..
Veli
the Telerik team

I just want the controls to work out fo the box, i.e percentage control with your grid..
Very basic stuff..
I have been hacking up fixes.. for this defect for many years ARG!!
You suggestion is just another of the many..
JUST FIX IT... once and for all; to save us ALL a lot of work fixing your broken control on each and evry page we use it..

This issue is also causing me a major headache. I have tried your example custom column class and it breaks when I try to do a postback. I have an example application that I would like to attach, however this thread won't let me do that, so here is the stack trace for the exception I get:
[GridException: Cannot create column with the specified type name: GridPercentColumn] Telerik.Web.UI.GridColumnCollection.CreateColumnFromTypeName(String columnTypeName) +1520 Telerik.Web.UI.GridColumnCollection.System.Web.UI.IStateManager.LoadViewState(Object savedState) +434 Telerik.Web.UI.GridTableView.LoadStructureState(Object SavedStructure) +366 Telerik.Web.UI.RadGrid.LoadTableViewStructure(IEnumerator stateEnumerator, GridTableView tableView) +101 Telerik.Web.UI.RadGrid.LoadViewState(Object savedStateObject) +281 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +187 System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +148 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +225 System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +148 System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +225 System.Web.UI.Page.LoadAllState() +312 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +747
I have to say after reading the history of this issue I'm appalled with Telerik's handling of it. I agree with Ray, the behavior of this control should be consistent with the globally accepted standard - not only for that reason, but more importantly because we can't use percentage-based columns consistently between edit mode and read-only mode. Let me explain our situation:
We are in the process of trialling an upgrade of our application from the Classic RadControls to the latest Prometheus controls (on .NET 4). Previously with the Classic controls, all we had to do was set the DataFormatString property on the GridBoundColumn object and the formatting would be consistent between edit mode and read-only mode. Now in the new controls that behavior has been stripped and the DataFormatString is no longer applied when in edit mode. This has been brought up in a previous post (see here) and answered such that we should apply the data format string manually to every grid in the application through the grid's ItemDataBound event - a stupid idea given that we probably have 50+ grids in our application which would need this change.
The suggested alternative to this is that we use GridNumericColumn. This would be an acceptable solution, however when using Percent as the numeric type there is now an inconsistency between how the datasource needs to present values between edit mode and read-only mode. Obviously our datasource can't be aware of what mode the grid cell is in so we would have to intercept this in the grid itself (again a stupid solution given the amount of grids we have in the application, and just shouldn't be necessary!!).
So finally Telerik provide a solution in the form of a custom column (which at the moment doesn't work) that in most developers minds would be considered a hack. Say this solution does eventually work, this extra code now becomes code that is now managed by us. What happens when Telerik make a change to the product which breaks this code? I can be sure that Telerik's response will be that this code - although provided by them - is not part of the product so is not supported. I mean what is the point in having a 3rd party product if we have to write custom code to fix deficiencies in the product??!!!
These comments are intentionally emotive, but have been seriously toned down from how I actually feel. For myself and the rest of the development community, that up until now have had nothing but praise for Telerik, a workable and sensible solution must be provided for this issue to restore our faith and continued use of this solution. Telerik team....over to you.

We cannot reproduce the error you have reported. We would surely like to look into this issue, if you manage to reproduce it again. If you can share some more info on your particular grid setup and column usage, we may be able to identify what's wrong.
As for "fixing" the numeric column, note that this would be a major breaking change affecting users that are already using the current column behavior. Instead, a property (turned off by default) can be introduced to alter the column behavior and use values from 0 to 1 for representing percentage.
In any case, you guys definitely have a say in what we build. I have notified the development team of this conversation and I believe they will consider your opinion. Additionally, I have created a PITS item for this feature where you guys can vote. Note that voting for this feature is important for us and is an effective way of influencing the decision to implement.
Veli
the Telerik team

Thanks for your reply. I've created a separate thread so that I am able to upload my example application which reproduces the issue I'm experiencing with your sample GridPercentColumn, see the following link:
http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=483791
I understand that Telerik can't simply change the code and break existing uses, so the suggested solution of adding a PercentType property to the GridNumericColumn class is perfectly acceptable. Thank you for moving this issue into the PITS area so it can be voted, but until either this development is done or the GridPercentColumn example works, we have no acceptable solution to this problem and as a result will not be upgrading from Classic to Prometheus (which also prevents us from upgrading from .NET 2 to 4!).
I notice that this issue has previously been moved there as item 1038 (mentioned here). I'm unable to find this item in PITS and am wondering what votes it previously had. Will the votes added to this previous item also count towards the new PITS item?
Regards
Callum
The previous issue seems to have been removed from PITS due to getting insufficient interest. It got one vote which we can add to the votes of this newly created PITS item.
As for your issue with the custom column, you are creating your columns programmatically in the Page_Load method of the page. When creating custom column programmatically, you need to use RadGrid's ColumnCreating event to create new instances of custom columns on postback:
protected
void
EmployeeGrid_ColumnCreating(
object
sender, GridColumnCreatingEventArgs e)
{
if
(e.ColumnType ==
"GridPercentColumn"
)
{
e.Column =
new
GridPercentColumn();
}
}
Using that event, RadGrid can now properly initialize your custom column. This should fix the problem.
Veli
the Telerik team

Hi Veli,
I see, that may be the case but again that puts us in the position of having to write code into every grid in the application to resolve this problem - a situation that is unacceptable to us (as I have already said). It seems to be a common theme in many of the posts I've seen in this forum, that the suggested solution for fixing problems with the grid is for the developer to patch it up by implementing some code in a grid event. Is it not recognized by Telerik that whenever this is required, that the developer may have to go through every grid in their application and do this? Do you realize how much pain that causes your community of developers? In my mind this is not acceptable practice and I question whoever is architecting this stuff as to whether they understand this. PLEASE provide a solution where I don't have to write code into every grid in my application. Until this happens we are not prepared to upgrade from the Classic controls and will have to look for a product that understands this simple concept.
Regards
Callum
Currently, any solution we may provide involves writing some amount of code in every grid. If the dev team decides to implement the proposed approach, there will be a single property you will have to set in each percentage formatted GridNumericColumn.
Veli
the Telerik team

public
void
SetGridColumns(RadGrid grid, GridConfig gridConfig)
{
foreach
(GridAttribute gridAttribute
in
gridConfig.GridAttributes)
{
this
.AddGridBoundColumn(grid, gridAttribute);
}
}
protected
void
AddGridBoundColumn(RadGrid grid, GridAttribute gridAttribute)
{
GridBoundColumn gridColumn =
new
GridBoundColumn();
grid.MasterTableView.Columns.Add(gridColumn);
gridColumn.UniqueName = gridAttribute.ID;
gridColumn.HeaderText = gridAttribute.SoftName;
gridColumn.DataType = gridAttribute.GetType();
gridColumn.DataField = gridAttribute.ID;
gridColumn.DataFormatString = gridAttribute.DataFormatString;
}
So what we do for each grid we put on a form is turn off the AutoGenerateColumns property and instead call the above SetGridColumns method (which resides in a class called GridBinder that is accessible to all web forms) from the non-postback section of the Page_Load event.
With the proposed change (and after upgrading from Classic to the new version of RadControls) the code would look more like this:
public
void
SetGridColumns(RadGrid grid, GridConfig gridConfig)
{
foreach
(GridAttribute gridAttribute
in
gridConfig.GridAttributes)
{
this
.AddGridBoundColumn(grid, gridAttribute);
}
}
protected
void
AddGridBoundColumn(RadGrid grid, GridAttribute gridAttribute)
{
GridBoundColumn gridColumn =
null
;
if
(gridAttribute.GetType() ==
typeof
(
decimal
))
{
gridColumn =
new
GridNumericColumn();
}
else
{
gridColumn =
new
GridBoundColumn();
}
grid.MasterTableView.Columns.Add(gridColumn);
gridColumn.UniqueName = gridAttribute.ID;
gridColumn.HeaderText = gridAttribute.SoftName;
gridColumn.DataType = gridAttribute.GetType();
gridColumn.DataField = gridAttribute.ID;
gridColumn.DataFormatString = gridAttribute.DataFormatString;
if
(gridColumn
is
GridNumericColumn)
{
GridNumericColumn numericColumn = gridColumn
as
GridNumericColumn;
switch
(gridAttribute.DataType)
{
case
DataTypeEnum.Percentage:
numericColumn.NumericType = NumericType.Percent;
numericColumn.GridPercentType = GridPercentType.FloatingPoint;
break
;
case
DataTypeEnum.Money:
numericColumn.NumericType = NumericType.Currency;
break
;
case
DataTypeEnum.Decimal:
numericColumn.NumericType = NumericType.Number;
break
;
}
}
}
Hopefully you can now see that with this type of solution we wouldn't need to write code into every grid of the application to resolve this problem.
Veli
the Telerik team

I came across this post while researching the same exact problem -- this is a bug. Percentages are often stored in 0-1 format in .NET and our underlying SQL db. It makes zero sense to have the RadNumericColumn have a NumericType="Percent" mode that simply shows a "%" sign. I'm forced to use the 0:p2 dataformatstring property...but this doesnt help on edit/filter textboxes, which for filtering improperly require one to type in this:
.95 %
...when trying to filter on 95 %, as the grid shows when using 0:p2 format.
It's a bug. It should have been fixed years ago. I'm disappointed that it hasn't.
Few releases ago we had introduced the DbValueFactor property of both RadNumericTextBox and GridNumericColumn. It should do the trick in your case.
Set DbValueFactor=100 for your column. And when you bind to database value like 0.15 it will be seen in the numeric text box as 15.
By default the factor is 1.
Regards,
Vasil
Telerik

Indeed the property apply only for the NumericTextBox in the edit item. The inputs in the filter item will not be affected. We will research it further and if it is possible will improve it.
Regards,
Vasil
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.


Here is what I came up with. Just add a GridNumericColumn with its NumericType=Percent, or adapt the code to better fit your needs. Since the item is correctly evalueted I expected the filtering item to work out of the box tho.
```
public partial class MyClass
{
private bool filtered = false;
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (filtered)
{
var arr = new GridColumn[RadGrid1.MasterTableView.Columns.Count];
RadGrid1.MasterTableView.Columns.CopyTo(arr, 0);
var filterItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem).First() as GridFilteringItem;
foreach (var c in arr)
{
bool isPercentColumn = c.ColumnType == "GridNumericColumn" && (c as GridNumericColumn).NumericType == NumericType.Percent;
if (isPercentColumn)
{
var textbox = filterItem[c.UniqueName].Controls.OfType<RadNumericTextBox>().First();
textbox.Value = textbox.Value * 100;
textbox.DbValue = textbox.Value;
RadGrid1.MasterTableView.GetColumn(c.UniqueName).CurrentFilterValue = textbox.Value.ToString();
}
}
filtered = false;
}
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
switch (e.CommandName)
{
case RadGrid.FilterCommandName:
var filterItem = e.Item as GridFilteringItem;
var arr = new GridColumn[RadGrid1.MasterTableView.Columns.Count];
RadGrid1.MasterTableView.Columns.CopyTo(arr, 0);
foreach (var c in arr)
{
var col = RadGrid1.MasterTableView.GetColumn(c.UniqueName);
bool isPercentColumn = col.ColumnType == "GridNumericColumn" && (col as GridNumericColumn).NumericType == NumericType.Percent;
if (isPercentColumn)
{
var textbox = filterItem[c.UniqueName].Controls.OfType<RadNumericTextBox>().First();
textbox.Value = textbox.Value / 100;
textbox.DbValue = textbox.Value;
RadGrid1.MasterTableView.GetColumn(c.UniqueName).CurrentFilterValue = textbox.Value.ToString();
}
}
filtered = true;
break;
default:
break;
}
}
}
```


Pretty much. I am using the 2018 release
@Vasil please delete my first post
Thank you for sharing your solution with the community. Your initial post has bed deleted as per your request.
Regards,
Vessy
Progress Telerik

Hi Vessy,
I use the following to display a decimal value as a Percentage, however, when I go to edit the row the decimal value is shown. For example, the grid row cell will show 100%, but when Editing the Cell value shown is 1 - this becomes quiet confusing to external Users. If a User sees a value of 100 they expect to edit the value of 100.
Is there a fix for this?
Thanks
<telerik:GridNumericColumn FilterControlWidth="50px" DataFormatString="{0:0.0%}" DataType="System.Double" DataField="C_C" FilterControlAltText="Filter C_C column" HeaderText="% Complete" SortExpression="C_C" UniqueName="C_C">
</telerik:GridNumericColumn>
Hi Alan,
You can try to set the DbValueFactor of the GridNumericColumn to 100. This should resolve the editing issue. See sample declaration below:
<telerik:GridNumericColumn DataField="Freight" FilterControlWidth="150px" DataFormatString="{0:0.0%}" DataType="System.Double" DbValueFactor="100"
FilterControlAltText="Filter Freight column" HeaderText="Freight"
SortExpression="Freight" UniqueName="Freight">
</telerik:GridNumericColumn>
To be able to filter by using the percentage values in this case you can try to manipulate the NumericTextBox in the FilteringItem in the following way:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
var filteringItem = e.Item as GridFilteringItem;
if (filteringItem != null)
{
var filterTextBox = filteringItem["Freight"].Controls[0] as RadNumericTextBox;
filterTextBox.DbValueFactor = 0.01;
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
GridFilteringItem filteringItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
var textBox = filteringItem["Freight"].Controls[0] as RadNumericTextBox;
var val = textBox.Value;
textBox.Value = val * 10000;
}
I have attached a test page for you to test the suggested above. You can add it to an existing Telerik Web site or just copy-paste the code in a new WebForm.
Please give it a try and let me know how this would work for you.
Kind regards,
Doncho
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.