简体   繁体   English

带有 HTML 和代码块的服务器标签

[英]Server Tags with HTML and Code Blocks inside

I'm trying to do something like this:我正在尝试做这样的事情:

<asp:ListItem><div><%= Message.Success %></div></asp:ListItem>

but it gives me this error:但它给了我这个错误:

ASP.NET runtime error: Code blocks are not supported in this context. ASP.NET 运行时错误:此上下文中不支持代码块。

Any ideas as to how to work around this error?关于如何解决此错误的任何想法?

You need a Binding Expression inside Controls <%# %> .您需要 Controls <%# %>内的绑定表达式。

<asp:ListView ID="ListView1" runat="server">
    <ItemTemplate>
        <div>
            <%# Message.Success %>
        </div>
    </ItemTemplate>
</asp:ListView>

However this does not work in a ListItem .但是,这在ListItem不起作用。 You will need to add that item with code if you want the Message.Success to be displayed.如果您希望显示Message.Success ,则需要使用代码添加该项目。

DropDownList1.Items.Add(new ListItem() { Text = Message.Success, Value = "0" });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM