I want to bind a grid to a collection of objects. Mostly I will just display properties of the objects. This is simple. But, I also want to display properties of those properties. Is that possible with the ultragrid? Has someone got an example somewhere? Is there instructions for doing this? In a sense what I am asking is how to display heirarchical object data in a flat grid.
This is an example of what I want to display
Task.User.UserName
Task.TaskDate
Task.Status.Description
Task.TaskNumber
etc.
I found a related post here, that relates to binding a list of complex objects (objects with nested sub-objects) and how to display them in stock asp:gridview control, but I am pretty sure the same principles can be tried with UltraWebGrid. The technique revolves around using templated columns and using databinding expressions to map to the respective complex sub-property, e.g. <%# Eval("User.UserName") %>
You just have to make sure you have public properties exposed for the properties you need to use.
More info can be found here:
http://www.velocityreviews.com/forums/t111794-bind-gridview-to-generic-custom-object-list-collection.html
Please, let me know if this helps.
Dude, I want to buy you a new car. That was fantastic! It worked first time. I was on the right track but I didn't realise you could do an Eval in side an ItemTemplate. Do you know how many times I've posted this question on microsoft forums with no response? It's been driving me nuts! Before I read your post I was half way through writing a routine to transform an object in to a datatable based on a transform string to flatten the structure. Truly awesome stuff! I'd been losing sleep on this one.
But now for the million dollar question. This solution works great for a simple read-only Microsoft GridView control. But will it work for a writable grid? Being able to display hierarchical data in this fashion is a huge step forward. But, it would be even more powerful if I could edit the data in the grid. Is that possible? It would be absoutely fantastic if the Infragistics grid supported this.
Yes, that would indeed come in handy. However, code-less create/read/update/delete (CRUD) operations on UltraWebGrid are supported only for declarative datasources like SqlDataSource, LinqDataSource, AccessDataSource, ObjectDataSource.
You can also do something semi-automatic for DataSets as well.
So I guess, you may try to indeed the datasource to Linq / ObjectDataSource if possible, or to DataSets,
Or
You can keep your current databinding collection and handle editing manually.
There are a lot of examples for both cases here
http://samples.infragistics.com/2008.2/webfeaturebrowser/default.htm
(in the Grid -> Editing section - full source code provideded there).