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

Rad Grid column formatting

3 Answers 711 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keshav
Top achievements
Rank 1
Keshav asked on 22 Jan 2016, 07:25 AM

Hi all ,

 

I have a requirement where I want the data in a currency column to be separated by commas. I have tried with different formats where i get commas but with '$' sign.I want commas with '$'. Any help is appreciated.

3 Answers, 1 is accepted

Sort by
0
Keshav
Top achievements
Rank 1
answered on 25 Jan 2016, 05:29 AM

I want commas without '$'.

#TypeError

 

Regards,

Anurag

0
Mansour
Top achievements
Rank 1
answered on 25 Jan 2016, 06:32 AM

You could try putting something like this in the grid's ItemBound event:

1.protected void rgUserAccess_ItemDataBound(object sender, GridItemEventArgs e)
2.{
3.    if (e.Item is GridDataItem)
4.    {
5.        var editItem = (GridDataItem)e.Item;
6.        editItem["price"].Text = int.Parse(editItem["price"].Text).ToString("000,000.00");
7.    }
8.}

0
Eyup
Telerik team
answered on 26 Jan 2016, 07:53 AM
Hi,

@Ali, Thank you for sharing your suggestion.

@Anurag, First of all, please make sure that you are not using DataBind() to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Programmatic Data Binding


As for the formatting requirement, you can achieve it using the formatting capabilities provided by .NET framework. For grid columns you can use the DataFormatString property:
Copy Code
<telerik:GridNumericColumn DataField="Freight" DataType="System.Decimal"
    FilterControlAltText="Filter Freight column" HeaderText="Freight"
    SortExpression="Freight" UniqueName="Freight" DataFormatString="{0:N0}">

For evaluated values you can use the String.Format(... / ...) method.

In addition, you can also check the following resources:
http://msdn.microsoft.com/en-us/library/dwhawy9k%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/0c899ak8%28v=vs.110%29.aspx


Hope this helps.


Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Keshav
Top achievements
Rank 1
Answers by
Keshav
Top achievements
Rank 1
Mansour
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or