简体   繁体   English

在文本中使用<>作为asp:DropDownList选项

[英]Using < > in text for asp:DropDownList option

I have the following in my .aspx file: 我的.aspx文件中包含以下内容:

    <asp:DropDownList ID="title" Width="350px" runat="server">
        <asp:ListItem Value="0">Please Select</asp:ListItem>
        <asp:ListItem Value="Dr">Dr</asp:ListItem>
        <asp:ListItem Value="Mr">Mr</asp:ListItem>
        <asp:ListItem Value="Ms">Ms</asp:ListItem>
        <asp:ListItem Value="Miss">Miss</asp:ListItem>
        <asp:ListItem Value="Mrs">Mrs</asp:ListItem>
    </asp:DropDownList>

I would like to put < > around "Please Select": 我想在“请选择”周围加上<>:

<asp:ListItem Value="0"><Please Select></asp:ListItem>

However, the file thinks I am opening a new tag when I use them. 但是,该文件认为我在使用它们时正在打开一个新标签。

Any ideas on how I can use these, possibly escaping them etc.,? 关于如何使用这些功能(可能将其转义等)的任何想法?

There's a Text attribute you can use for the text instead of putting the text between the opening and closing tags: 有一个Text属性可用于文本,而不是将文本放在开始和结束标记之间:

<asp:ListItem Value="0" Text="<Please Select>" />

You can also use the HTML entities if you prefer: 如果愿意,还可以使用HTML实体:

<asp:ListItem Value="0" Text="&lt;Please Select&gt;" />

You can use HttpServerUtility.HtmlEncode function 您可以使用HttpServerUtility.HtmlEncode函数

String TestString = "This is a <Test String>.";
String EncodedString = Server.HtmlEncode(TestString);

msdn link : http://msdn.microsoft.com/fr-fr/library/vstudio/w3te6wfz.aspx msdn链接: http : //msdn.microsoft.com/fr-fr/library/vstudio/w3te6wfz.aspx

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

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