I need to build a grid where the rows can expand and collapse in a similar fashion to a RadPanelBar and have started to look at NestedViews for the grid.
The idea being that I load a set of data and load it into my grid, and for each item I can have additional information in controls in my nestedview. The controls in my NestedView will always be in an editable state.
However, I can only use webservices as my data source, and while loading data for the grid is simple enough (OnNeedDataSource) it seems that this is not an option for the nested view.
I have thought about actually using a RadPanelBar, but the RadPanelItems would need to have alternate colours etc and it just seems like an awful lot of work, so I'm hoping there's a simple solution out there that I've missed.
The idea being that I load a set of data and load it into my grid, and for each item I can have additional information in controls in my nestedview. The controls in my NestedView will always be in an editable state.
However, I can only use webservices as my data source, and while loading data for the grid is simple enough (OnNeedDataSource) it seems that this is not an option for the nested view.
I have thought about actually using a RadPanelBar, but the RadPanelItems would need to have alternate colours etc and it just seems like an awful lot of work, so I'm hoping there's a simple solution out there that I've missed.
6 Answers, 1 is accepted
0
Hi Karl,
Do you bind RadGrid on the server? If this is the case, there are quite many ways to bind the nested view in RadGrid. Once you define your controls in the NestedViewTemplate, they will all fire their DataBinding event when the nested view item is to be databound. Alternatively, you can use a custom UserControl inside the nested template. The user control will fire its DataBinding event which you can use to set control properties or bind them to data.
If you need to access the parent data item and its data object during data binding, note that the NamingContainer of every control inside the nested view template is the GridNestedViewItem instance that holds your controls. You can cast the naming container to this type and use the item's ParentItem property to get the parent GridDataItem.
Veli
the Telerik team
Do you bind RadGrid on the server? If this is the case, there are quite many ways to bind the nested view in RadGrid. Once you define your controls in the NestedViewTemplate, they will all fire their DataBinding event when the nested view item is to be databound. Alternatively, you can use a custom UserControl inside the nested template. The user control will fire its DataBinding event which you can use to set control properties or bind them to data.
If you need to access the parent data item and its data object during data binding, note that the NamingContainer of every control inside the nested view template is the GridNestedViewItem instance that holds your controls. You can cast the naming container to this type and use the item's ParentItem property to get the parent GridDataItem.
Veli
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0

Karl
Top achievements
Rank 1
answered on 17 Mar 2011, 10:30 AM
I do, but the list of objects I bind to have lists within them and it's these internal lists I want to show in my nested view.
Are there any working examples of this that I can look at to properly understand the process?
Thanks.
Are there any working examples of this that I can look at to properly understand the process?
Thanks.
0
Yes, look at the attached test project (Telerik.Web.UI assembly omitted). RadGrid's NestedViewTemplate contains a user control. Inside the user control I can have whatever I need. The important part is the overridden OnDataBinding method of the user control which calls the following method:
This is how we get the parent item's DataItem, cast it to the respective type and use any properties we need from it. In our case, I have implemented a DataItem property for my own user control, so that the data source is available throughout the control life cycle. I can then bind a DetailsView or any other control to this data.
Veli
the Telerik team
private
void
RetrieveDataSourceFromParentItem()
{
//this user control is initialized in a GridNestedViewItem instance
//and this item is the NamingContainer of the user control
GridNestedViewItem nestedItem = NamingContainer
as
GridNestedViewItem;
if
(nestedItem !=
null
)
{
//the parent RadGrid data item is bound to an object of type MyData.BusinessObjectCategory
//this data object contains a list of items in its Items property
//this is how I specify this user control's DataSource to point to the parent Items collection
MyData.BusinessObjectCategory parentDataItem = nestedItem.ParentItem.DataItem
as
MyData.BusinessObjectCategory;
if
(parentDataItem !=
null
)
{
DataSource = parentDataItem.Items;
}
}
}
This is how we get the parent item's DataItem, cast it to the respective type and use any properties we need from it. In our case, I have implemented a DataItem property for my own user control, so that the data source is available throughout the control life cycle. I can then bind a DetailsView or any other control to this data.
Veli
the Telerik team
0

Karl
Top achievements
Rank 1
answered on 25 Mar 2011, 05:38 PM
Thanks Veli,
This is the kind of thing I want to accomplish.There is a curve ball however...
I need to add a dynamic number of controls (editable textboxes) to to my nestedviewtemplate control when my main data gets bound. Each item that gets bound has a number of additional fields that changes from dataset to dataset and it's these I want to show in my nestedview. I seem to be able to add the controls and labels etc ok (no errors are produced) but when I go to expand any of my grid rows, there's nothing in the nested view.
It seems that because the grid posts back when you click the icon to expand the row, all the controls I added in the nestedview template when I databound the first time the page was hit arent there any more. this makes sense, but how to I apply these "templates" each time the page postsback AND retain any values that were entered into them?
Thanks,
Karl
This is the kind of thing I want to accomplish.There is a curve ball however...
I need to add a dynamic number of controls (editable textboxes) to to my nestedviewtemplate control when my main data gets bound. Each item that gets bound has a number of additional fields that changes from dataset to dataset and it's these I want to show in my nestedview. I seem to be able to add the controls and labels etc ok (no errors are produced) but when I go to expand any of my grid rows, there's nothing in the nested view.
It seems that because the grid posts back when you click the icon to expand the row, all the controls I added in the nestedview template when I databound the first time the page was hit arent there any more. this makes sense, but how to I apply these "templates" each time the page postsback AND retain any values that were entered into them?
Thanks,
Karl
0

Karl
Top achievements
Rank 1
answered on 25 Mar 2011, 06:20 PM
Update. I've just looked through the source on my rendered page and there's no mention of my template item, so I'm not really sure if the template is actually being applied.
0
If you are losing your controls on postback, this means the controls are not properly recreated. Note that you need to create controls dynamically in your user control on every postback. If you are using the DataBinding or DataBound events for control initialization, note that these events will not fire on every postback. The control structure of your user control needs to be recreated exactly in the state it was at the end of the previous page life cycle. This needs to happen before the ViewState is loaded into the user control. For more information on dynamic control initialization and state management, refer to the Dynamic Web Server Controls and ViewState MSDN topic and related links.
Veli
the Telerik team
Veli
the Telerik team