c# - 无法将数据绑定(bind)到中继器内的标签

标签 c# asp.net repeater

我的代码是这样的

<asp:Repeater ID="rptEvaluationInfo" runat="server">
<ItemTemplate>
   <asp:Label runat="server" Id="lblCampCode" Text="<%#Eval("CampCode") %>"></asp:Label>

</ItemTemplate>

对我来说一切看起来都很好,但它在运行时生成了一个错误。当我删除这部分时

Text="<%#Eval("CampCode") %>" 

错误发生。 所以我认为问题出在数据绑定(bind)上。所以我尝试了这样的替代方案

    <asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
    <label><%#Eval("CampCode") %> </label>

</ItemTemplate>

而且效果也很好。谁能告诉我我的第一个代码有什么问题吗?

Note: I don't have access to the error message due to the special reasons on my project , that's why I have not posted it here. And I want to use ASP controls itself on the case that's why i haven't gone with my second solution

最佳答案

问题出在引号上。目前,到处都有双引号,因此 ASP.NET 无法解析它。将外部的单引号更改为单引号,如下所示:

Text='<%#Eval("CampCode") %>'

关于c# - 无法将数据绑定(bind)到中继器内的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25310281/

相关文章:

asp.net - 如何在 IIS 7.0 上增加线程池线程

c# - FlickrNet API - 从 PhotoSearch 获取集合名称

c# - .NET (C#) 应用程序插件的依赖 hell

asp.net - 在 ASP.Net 中为不同的 session 变量设置不同的超时

c# - 数字表 Oracle 存储过程参数,如何从 C# 传递它

asp.net - 检测并显示 IE8,然后使用 MVC 3 Razor 显示现有的 IE8 css 样式表

c# - 如何使用嵌套中继器获取代码后面的页脚项值?

c# - 使用中继器控件不会触发 ItemCommand 事件

c# - 如何在 List<string> 项中搜索

c# - 将新节点添加到 xml 末尾的最快方法?