0
我想为我的自定义FormView控件中的编辑/插入和视图设置一个模板。但我得到这些奇数例外窗体视图和外部IBindableTemplate
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.Table'.
public class CustomFormView : FormView
{
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(FormView), BindingDirection.TwoWay)]
public IBindableTemplate FormTemplate { get; set; }
protected override void OnInit(EventArgs e)
{
ChangeMode(FormViewMode.Edit);
if (FormTemplate != null)
{
if (CurrentMode == FormViewMode.Edit)
{
FormTemplate.InstantiateIn(this);
}
}
base.OnInit(e);
}
}
编辑:
在第一步骤中,我创建的新用户控制和引用加到一个FormView( “FV”)
public partial class Form : UserControl
{
private IBindableTemplate _template = null;
[PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(FormView), System.ComponentModel.BindingDirection.TwoWay)]
public IBindableTemplate FormTemplate { set;get }
protected void Page_Init()
{
if (FormTemplate != null)
{
FV.InsertItemTemplate = FV.EditItemTemplate = FormTemplate;
if (!IsPostBack) FormTemplate.InstantiateIn(FV);
}
}
}
现在,我想将此用户控件转换为我们b控制。
如果您能回复我的问题,我将不胜感激。
亲爱的Jeroen,感谢您的回复,我已更改我的帖子,请您帮我找到解决方案,谢谢。 – Mironline 2010-08-17 21:18:55
为什么你想要一个模板?你想使用1个模板进行编辑和插入吗? – Jeroen 2010-08-17 21:43:36
确切地说,我不是真的有兴趣创建一个独特的模板的属性,是否有可能克隆“插入模板”,并设置编辑的模板?!或某事。喜欢这个 ?谢谢 - – Mironline 2010-08-18 07:43:21