Can't use Bind in RadGrid FormTemplate in custom control
Hello
I have a custom control that is using a RadGrid that uses a Linqdatasouce to one of our external databases. I'm trying to use a EditTemplate, but any control within that template that uses a <%# %> expression causes the error below:
This occurs in textboxes with a
Text='<%# Bind("Id") %>'
<
asp:Button
ID
=
"btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></
asp:Button
>
[ArgumentNullException: Value cannot be null.
Parameter name: expression]
System.Web.UI.DataBinder.Eval(Object container, String expression) +8705859
System.Web.UI.DataBinder.Eval(Object container, String expression, String format) +12
Telerik.Sitefinity.Web.UI.Templates.Attribute.GetValue(SubstitutionItem subst, Control bindingContainer) +515
Telerik.Sitefinity.Web.UI.Templates.Attribute.GetValue(PropertyDescriptor descriptor, Control bindingContainer) +53
Telerik.Sitefinity.Web.UI.Templates.Attribute.SetAttribute(Object component, Control bindingContainer, Boolean bound) +167
Telerik.Sitefinity.Web.UI.Templates.BoundAttribute.bindingContainer_DataBinding(Object sender, EventArgs e) +20
System.Web.UI.Control.OnDataBinding(EventArgs e) +91
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +201
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +201
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
System.Web.UI.Control.DataBind() +15
System.Web.UI.Control.DataBindChildren() +201
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +101
System.Web.UI.Control.DataBind() +15
Telerik.Web.UI.GridEditFormItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +238
Telerik.Web.UI.GridTableView.CreateInsertItem(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ControlCollection rows) +320
Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1118
Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +652
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +66
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +128
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
Telerik.Web.UI.GridTableView.PerformSelect() +16
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
Telerik.Web.UI.GridTableView.DataBind() +256
Telerik.Web.UI.GridTableView.Rebind() +49
Telerik.Web.UI.GridTableView.InsertItem(IDictionary newValues) +147
Telerik.Web.UI.GridTableView.InsertItem() +15
Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source) +3089
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +137
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +38
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +87
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Hi Ryan,
If you use our template parser for your control it is not possible to use expression like this one shown in your code
<
asp:Button
ID
=
"btnUpdate"
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></
asp:Button
>
public
override
string
LayoutTemplatePath
get
return
"~/sfres/Telerik.Sitefinity.Resources.Templates.Backend.MyGrid.ascx"
;
set
base
.LayoutTemplatePath = value;
Is there any further documentation/examples of this anywhere because I've added an override for LayoutTemplatePath and it can't find the template. I've searched through the SDK examples and How to's and can't find anything. The template is an embedded resource, is this incorrect?
Hi Ivan
I still can't get this to work. Is the ascx control still meant to be an embedded resource, and if not, where does it need to be placed in order to be found?
Thanks
Ryan[ArgumentException: Cannot find template "/SFRes/Test.Resources.Views.TestView.ascx".]
Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(String virtualPath, String resourceFileName, Type assemblyInfo, String templateDeclaration) +850
Telerik.Sitefinity.Web.UI.ControlUtilities.GetControlTemplate(TemplateInfo info) +446
Telerik.Sitefinity.Web.UI.ControlUtilities.GetTemplate(TemplateInfo info) +790
Telerik.Sitefinity.Web.UI.SimpleView.get_LayoutTemplate() +119
Telerik.Sitefinity.Web.UI.SimpleView.get_Container() +21
Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +46
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
Hi Ryan,
When you use Virtual Path provider the template should be embedded, but you should configure some settings from Sitefinity >> Administration >> Settings >> Advanced >> VirtualPathSettings >> Virtual Paths. You need to set VirtualPath - path to the template and ResourceLocation - namespace and assembly name of your class library.
If you do not use embedded resource the template could be added to a folder of your application and it should be processes by ASP.NET parser.
Regards,
Ivan Dimitrov
the Telerik team
I can't access the VirtualPathSettings node, it seems to get stuck in a loop on both IE and Firefox. Just says "loading".
I've tried adding a VirtualPathSettingsConfig.config into the Configuration directory, but that hasn't helped either.
Thanks Ivan,
I got the custom module working with LayoutTemplatePath now by manually editing the VirtualPathSettingsConfig.config.
Is there a way of programmatically adding this setting during the module installation?
(the issue remains in the backend that i can not access the VirtualPath settings as it is stuck in a loop but it's not preventing me from continuing for the moment)
Ryan
Hello Ryan,
I remember that there was a bug with the way that the node is expanded, but it should be fixed in our internal builds.
Kind regards,
Ivan Dimitrov
the Telerik team