首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >表单视图和外部IBindableTemplate

表单视图和外部IBindableTemplate
EN

Stack Overflow用户
提问于 2010-08-17 10:54:44
回答 1查看 587关注 0票数 0

我想在我的自定义FormView控件中设置一个用于编辑/插入和查看的模板。但我有个奇怪的例外

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.Table'.

代码语言:javascript
运行
复制
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")

代码语言:javascript
运行
复制
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);
        }
    }
}

现在,我想将这个用户控件转换为web控件。

如果你能回答我的问题,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2010-08-17 13:13:32

你到底想做什么??

不管你想做什么,你都做错了。

TemplateContainer(typeof(FormView))这是不可能的。

您需要在那里提供您自己的类型,从IDataItemContainer继承。

编辑:

我不建议仅仅因为你想有一个模板来编辑和插入,就把所有这些工作都做好了。最好将相同的内容放在两个模板中。经验告诉我们,随着时间的推移,您将需要不同的功能来编辑和插入。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3501623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档