If I'm using FormTemplates to edit and insert records, is it possible to specify different FormTemplates depending on the selected node?
I'm trying to use the TreeList to display entities from various different tables.
As an example, let's say that I have 3 underlying SQL tables for Customer, Employee, Suppliers. Each table contains different fields.
I've created a top level stored procedure that provides 'grouping' rows and unions the data into the following structure.
NodeId, ParentNodeId, Firstname, PersonType
I can successfully bind this to my TreeList and the top level nodes allow me to drill down to Customer, Employee and Supplier. However, I need to be able to specify different form templates depending on the parent node.
Is it possible to do this?
Let me know if any of this is not clear.
Thanks,
Tim
I'm trying to use the TreeList to display entities from various different tables.
As an example, let's say that I have 3 underlying SQL tables for Customer, Employee, Suppliers. Each table contains different fields.
I've created a top level stored procedure that provides 'grouping' rows and unions the data into the following structure.
NodeId, ParentNodeId, Firstname, PersonType
I can successfully bind this to my TreeList and the top level nodes allow me to drill down to Customer, Employee and Supplier. However, I need to be able to specify different form templates depending on the parent node.
Is it possible to do this?
Let me know if any of this is not clear.
Thanks,
Tim
3 Answers, 1 is accepted
0
Tim
Top achievements
Rank 1
answered on 08 Jul 2011, 03:47 PM
I'm trying to see whether or not I can achieve this by using WebUserControls and writing code in some event to switch the control that is used.
I'm following these instructions.
http://www.telerik.com/help/aspnet-ajax/treelist-editform-types.html
When I click on the edit link, I get the following exception:
Exception Details: System.NotSupportedException: Cannot extract values from item when EditFormType is WebUserControl.
Source Error:
Stack Trace:
Here's my code:
The ASCX contains is pretty much empty.
Can someone see what's wrong here?
Tim
I'm following these instructions.
http://www.telerik.com/help/aspnet-ajax/treelist-editform-types.html
When I click on the edit link, I get the following exception:
Cannot extract values from item when EditFormType is WebUserControl.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NotSupportedException: Cannot extract values from item when EditFormType is WebUserControl.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[NotSupportedException: Cannot extract values from item when EditFormType is WebUserControl.] |
Here's my code:
<
telerik:RadTreeList
ID
=
"RadTreeList1"
runat
=
"server"
AllowMultiItemEdit
=
"False"
AutoGenerateColumns
=
"False"
Culture
=
"(Default)"
DataKeyNames
=
"UniqueID"
DataSourceID
=
"dsTreeSQL"
IsItemInserted
=
"False"
ParentDataKeyNames
=
"ParentID"
ShowOuterBorders
=
"False"
>
<
EditFormSettings
EditFormType
=
"WebUserControl"
UserControlPath
=
"ctrlBusinessArea.ascx"
>
</
EditFormSettings
>
<
Columns
>
<
telerik:TreeListBoundColumn
DataField
=
"NodeText"
HeaderText
=
"Business Explorer"
UniqueName
=
"column"
>
<
HeaderStyle
Font-Bold
=
"True"
/>
</
telerik:TreeListBoundColumn
>
<
telerik:TreeListEditCommandColumn
>
</
telerik:TreeListEditCommandColumn
>
</
Columns
>
</
telerik:RadTreeList
>
The ASCX contains is pretty much empty.
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ctrlBusinessArea.ascx.vb" Inherits="Content_Tools_ctrlBusinessArea" %>
Business Area
Can someone see what's wrong here?
Tim
0
Accepted
Hello Tim,
I have reported the exception you are getting to the dev team and they will be looking at it. As a workaround to using a WebUserControl for this scenario, you need to implement the IBindableControl interface in your user control:
If you do not have any values to extract from the user control, simply leave the ExtractValues empty.
As for using different edit forms for different data items in RadTreeList, you can implement the scenario both with the FormTemplate and with a custom WebUserControl. In both cases, you need to define all your possible different edit forms. If you are using the FormTemplate feature, define different edit form content in different panels for example. Then, depending on the edited item, you can show some panels and hide others. You use the ItemDataBound event for that:
Alternatively, if you are using WebUserControls, you need to define 1 master user control to specify as RadTreeList's edit form. In your test case, for example, the ctrlBusinessArea can be your master user control. Then, either define different panels inside for the different edit forms (like in the above FormTemplate case), or define different nested user controls. You again show/hide them depending on the edited item. To get the RadTreeList edit form item from inside the user control, you can use the OnDataBinding overload:
Greetings,
Veli
the Telerik team
I have reported the exception you are getting to the dev team and they will be looking at it. As a workaround to using a WebUserControl for this scenario, you need to implement the IBindableControl interface in your user control:
public
partial
class
ctrlBusinessArea : System.Web.UI.UserControl, IBindableControl
{
#region IBindableControl Members
public
void
ExtractValues(System.Collections.Specialized.IOrderedDictionary dictionary)
{
//
}
#endregion
}
If you do not have any values to extract from the user control, simply leave the ExtractValues empty.
As for using different edit forms for different data items in RadTreeList, you can implement the scenario both with the FormTemplate and with a custom WebUserControl. In both cases, you need to define all your possible different edit forms. If you are using the FormTemplate feature, define different edit form content in different panels for example. Then, depending on the edited item, you can show some panels and hide others. You use the ItemDataBound event for that:
protected
void
RadTreeList1_ItemDataBound(
object
sender, TreeListItemDataBoundEventArgs e)
{
if
(e.Item
is
TreeListEditFormItem)
{
var editFormItem = (TreeListEditFormItem)e.Item;
if
(editFormItem.IsInEditMode)
{
//this is your parent data item. Use it to identify the type of edit form
var dataItem = editFormItem.ParentItem;
//then find controls in editFormItem.EditFormCell and hide/show them accordingly
}
}
}
Alternatively, if you are using WebUserControls, you need to define 1 master user control to specify as RadTreeList's edit form. In your test case, for example, the ctrlBusinessArea can be your master user control. Then, either define different panels inside for the different edit forms (like in the above FormTemplate case), or define different nested user controls. You again show/hide them depending on the edited item. To get the RadTreeList edit form item from inside the user control, you can use the OnDataBinding overload:
protected
override
void
OnDataBinding(EventArgs e)
{
base
.OnDataBinding(e);
//this is your treelist edit form item. use it to identify the edit form to show
var editFormItem = (TreeListEditFormItem)
this
.NamingContainer;
}
Greetings,
Veli
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
0
Tim
Top achievements
Rank 1
answered on 13 Jul 2011, 10:37 AM
Hi Veli
Thanks for workaround
Tim
Thanks for workaround
Tim