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

[Solved] DataFormatString Not Formatting the Value

1 Answer 337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tae Lee
Top achievements
Rank 1
Tae Lee asked on 03 Mar 2010, 12:19 AM

 

I have a RadGrid using XML file as data source and the field on this XML file is not formatted.  We need to format the value in the field as percentage with two decimal digits and I have coded as shown below:

        <telerik:GridBoundColumn DataField="Percentage" HeaderText="Percentage" SortExpression="Percentage"   
            UniqueName="Percentage" DataFormatString="{0:#####.## %}"   
            EditFormHeaderTextFormat="{0:#####.## %}" > 
        </telerik:GridBoundColumn> 

However, no matter what I change on the DataFormatString the value shows without formatting.  Can you please help?  Thank you.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Mar 2010, 09:11 AM
Hi,

You need to set the format from the code as shown below:

C#
 protected void RadGrid3_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            decimal dcimalPercentage =Convert.ToDecimal(dataItem["Value"].Text); 
            dataItem["Value"].Text = String.Format("{0:#.#}", dcimalPercentage); 
              
        } 
    } 


Please  refer to the link that discusses on  Using DataFormatString with attribute values of bound XML datasource .You will find the necessary information under the Community content.

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