c# 无法识别 eval if

问题描述 投票:0回答:1

Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据受限的控制上下文中使用。

解释:执行当前 Web 请求时发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.InvalidOperationException:Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件上下文中使用。

来源错误:

Satır 306: </div>
Satır 307: <div class="pl-0 pl-md-4 mt-3 mt-md-0">
Satır 308:     <% if (Eval("services_longtitle").ToString() == "Google Ads Services") { %>
Satır 309:     <p class="h4"><%# Eval ("services_sectiontitle") %></p>
Satır 310:     <% } %>
c# .net eval
1个回答
0
投票

如果您尝试在数据绑定控件之外使用此代码,您可能需要考虑在支持数据绑定的控件(例如 GridView、Repeater、DataList 等)中使用它。

这是一个使用 GridView 的示例..

<asp:GridView ID="yourGridView" runat="server" AutoGenerateColumns="False">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <%# Eval("services_longtitle") != null && Eval("services_longtitle").ToString() == "Google Ads Services" ? "<p class='h4'>" + Eval("services_sectiontitle") + "</p>" : "" %>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
© www.soinside.com 2019 - 2024. All rights reserved.