Earlier this week while working on another blog entry, I ran into a unique situation involving the RadGridView. Basically, what I am doing is retrieving user status data from Facebook using the Facebook Developer Toolkit. The data is returned in a list of objects based on the Facebook API schema. These objects are of type user_status and contain the following:
uuid - long
status_id - long
time - long
source - string
message - string
comment_count - int
I basically wanted to take this list and bind it to the RadGridView showing only the message and the time for that message. This was pretty easy to do using basic DataBinding. I've created an example of this situation using my own custom objects and test data:
As you can see in my test data, the time values are giant number values?! Why is this? Well, the reason for this is that Facebook is actually returning times in Unix time. Unix time is the number of seconds that has elapsed since January 1st, 1970. You can read more about this here. Displaying this data is no good to me, nobody is going to want to calculate the date of a status update in their head using the number of seconds. Luckily, the RadGridView is equipped to handle this type of situation via the CellFormatting event.
Using the CellFormatting event, I can easily retrieve the current value of a particular cell, i.e. Unix time, and format it to be displayed in human readable DateTime format. All without changing the value stored in the underlying datasource. This saves me some time since I now don't have to convert the object manually, use a wrapper class, or populate the grid values manually. Pretty useful eh?
Click here to download the source code used in this post.
Subscribe to be the first to get our expert-written articles and tutorials for developers!