asp.net中的DataBinder.Eval错误
我创建了一个类来执行一些任务,比如GridView继承自System.Web.UI.WebControl.WebControlasp.net中的DataBinder.Eval错误,asp.net,repeater,databinder,Asp.net,Repeater,Databinder,我创建了一个类来执行一些任务,比如GridView继承自System.Web.UI.WebControl.WebControl public class IHGridView : System.Web.UI.WebControls.WebControl { // inside here, actually return Repeater class. protected override void OnInit(EventArgs e) { _repe
public class IHGridView : System.Web.UI.WebControls.WebControl
{
// inside here, actually return Repeater class.
protected override void OnInit(EventArgs e)
{
_repeater.ItemTemplate = new IHGridItemTemplate(ListItemType.Item, this.Columns);
this.Controls.Add(_repeater);
}
}
我还在IHGridView中为我的中继器创建了ItemTemplate
public class IHGridItemTemplate : ITemplate
{
}
IHGridView类返回Repeater和一些html代码,但为了方便开发,我创建了一些东西
public class Columns : StateManagedCollection
{
}
public class IHBoundFieldBase : IStateManager
{
}
public class IHLabelField : IHBoundFieldBase
{
}
现在在我的aspx中,我可以像下面这样使用它:
<cc1:IHGridView ID="IHGridView1" runat="server" EditMode="View">
<Columns>
<cc1:IHLabelField ID="IHLabelField7" DataField="PERSON_NAME" HeaderText="PersonName" />
</Columns>
</cc1:IHGridView>
现在我想到一个问题。
我无法在aspx中使用DataBinder.Eval
<cc1:IHLabelField ID="IHLabelField7" HeaderText="PersonName" Text='<%# DataBinder.Eval(Container.DataItem, "PERSON_NAME") %>' />
这给了我一个错误。
错误消息如下:“System.Web.UI.Control”中没有“DataItem”的定义。System.Web.UI.Control的第一个参数中没有可扩展方法“DataItem”。请检查是否有使用量规或装配参考。这是用韩语写的,但我翻译成了英语。
谁能给我一个解决这个问题的线索吗?在模板控件中,模板在容器中实例化。对于要在模板化字段中工作的数据绑定,建议容器应实现接口-接口实现应提供数据项 另外,为了支持数据绑定表达式,ASP.NET解析器为控件(其属性使用这些表达式)的
DataBinding
事件注入处理程序,然后在处理程序中生成在容器中查找数据项的代码
因此,在您的示例中,如果希望在
IHLabelField.Text
属性中使用数据绑定表达式,则控件的命名容器应实现IDataItemContainer
或具有DataItem
属性。因此,在本例中,您可能需要IHGridView
控件上的DataItem
,但它无法按您想要的方式工作 下面是我们使用的一个示例。我希望有帮助