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

Binding to ArrayList - trouble changing DataType

1 Answer 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kasey
Top achievements
Rank 1
Kasey asked on 15 Mar 2011, 11:50 PM
Hello,

I'm currently putting results of a Web Service call, into an ArrayList and binding successfully (columns auto generated). During binding I hide certain columns and the next step is to start formatting. I've looked through numerous articles on using OnColumnCreated/Creating, PreRender, and whatever I do to change the DataFormatString and DataType doesn't work when sorting. I'm trying to format the Amount column as System.Decimal, format as currency and sort but it is still sorting as a string (the native type in ArrayList).

EDIT: Over the course of a day I've done better troubleshooting and found that I expected the grid to convert values to the specific DataType. In my case, all JSON deserialized types were System.String. I now convert from IList to DataTable and change the DataType of the Amount column before populated. This works and sorts correctly now. Hope that helps someone.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 19 Mar 2011, 09:46 AM
Hi Richard,

Your observations are correct. RadGrid does not convert between data types. If you specify a DataType for your column, the grid will try to cast the data values of that column to the specified data type. No conversion is performed, though. Therefore, you need to specify a data type to which data values for the specified column can be cast. If you omit to specify the DataType for a column, the type of the respective data field or property from the data source will be assigned.

Veli
the Telerik team
Tags
Grid
Asked by
Kasey
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or