簡體   English   中英

在文本中使用<>作為asp:DropDownList選項

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

我的.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>

我想在“請選擇”周圍加上<>:

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

但是,該文件認為我在使用它們時正在打開一個新標簽。

關於如何使用這些功能(可能將其轉義等)的任何想法?

有一個Text屬性可用於文本,而不是將文本放在開始和結束標記之間:

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

如果願意,還可以使用HTML實體:

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

您可以使用HttpServerUtility.HtmlEncode函數

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

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