在任何模板化控件上共享相同的ITemplate [英] Sharing same ITemplate across any Templated control

查看:55
本文介绍了在任何模板化控件上共享相同的ITemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用常见的Itemplate类动态生成Gridview和Detailsview的模板化控件。我使用的方法类似于描述

此处 [ ^ ]。但是,在数据绑定事件期间,我必须明确指定被绑定的控件的类型。例如,


Hi,
I am trying to use a common Itemplate class for dynamic generation of Templated controls for both Gridview and Detailsview.I am using an approach similar to described
here[^]. However, during databinding event, I have to explicitly specify the type of control being binded. For e.g

DropDownList dropdown = (DropDownList)sender;
            GridViewRow container = (GridViewRow)dropdown.NamingContainer; <-- Problem lies here
            object dataValue = DataBinder.Eval(container.DataItem, _columnName);





有没有任何我可以使用接口访问NamingContainer并将其传递给DataBinder.Eval函数以提取基础数据项值的选项?



Is there any option where i can use an interface to access the NamingContainer and pass it to the DataBinder.Eval function to extract the underlying data item value ?

推荐答案

得到解决方案,以下是相同的代码。这适用于任何模板控件





Got the solution, following is the code for the same. This works for any Templated control


IDataItemContainer container = (IDataItemContainer)txt.NamingContainer;
           object dataValue = DataBinder.Eval(container.DataItem, _columnName);


这篇关于在任何模板化控件上共享相同的ITemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆