asp.net中的数据绑定表达式

asp.net中的数据绑定表达式,asp.net,data-binding,repeater,Asp.net,Data Binding,Repeater,我有一个VS2005 ASP.Net页面,上面有一个客户的转发器 中继器的屏幕上显示以下内容: <span><%# Eval(GetAdLinks((Customer)Container.DataItem)) %></span> GetAdLinks是代码隐藏中的一个受保护方法,它返回一个表示为字符串的控件。这可能吗 我得到一个错误,说客户不包含名为 有什么想法吗?如果它是一个客户端no-runat=server控件,那么它应该是可能的。但你不应该把它包括在

我有一个VS2005 ASP.Net页面,上面有一个客户的转发器

中继器的屏幕上显示以下内容:

<span><%# Eval(GetAdLinks((Customer)Container.DataItem)) %></span>
GetAdLinks是代码隐藏中的一个受保护方法,它返回一个表示为字符串的控件。这可能吗

我得到一个错误,说客户不包含名为


有什么想法吗?

如果它是一个客户端no-runat=server控件,那么它应该是可能的。但你不应该把它包括在评估中。我猜应该是这样的:

<%# GetAdLinks(Container.DataItem) %>
应重构GetAdLinks方法以接受Container.DataItem作为DataRowView对象。在方法内部,您可以将其强制转换为Customer对象,只需稍加调试即可解决


祝你好运

更好的方法是在Repeater模板中添加一个文本,然后实现OnDataBinding方法。这正是文字的意义所在

以下是一个例子:

<asp:Literal ID="litYourControl" runat="server" OnDataBinding="litYourControl_DataBinding" />

你能为GetAdLinks方法发布签名吗?
protected void litYourControl(object sender, System.EventArgs e)
{
    Literal lt = (Literal)(sender);
    // Not sure what field you are binding to based on the example in your question
    // so I will just make an assumption.
    Customer cus = (Customer)(Eval("Container.DataItem"));
    lt.Text = GetAdLinks(cus);
}