简体   繁体   English

如何使用html标签在C#Dropdownlist中显示Superscript

[英]How to display a Superscript in C# Dropdownlist, using html tags

Hope someone can tell me how I should get a Superscript tag like ² to display correctly in the text of a Dropdownlist option? 希望有人能告诉我如何在下拉列表选项的文本中正确显示像²这样的Superscript标签?

Thanks. 谢谢。

Probably using HTML entities: 可能使用HTML实体:

²

instead of the actual character. 而不是实际的角色。 But it's probably better to let C# take care of it: 但让C#处理它可能更好:

string safeString = HttpUtility.HtmlEncode("your string²");
// Use the result as the displayed value in your Dropdownlist

This method will also find other problematic characters such as & and replace them accordingly. 此方法还会找到其他有问题的字符,例如&,并相应地替换它们。 See MSDN HttpUtility.HtmlEncode for more information on this. 有关详细信息,请参阅MSDN HttpUtility.HtmlEncode

Edit : be advised; 编辑 :被告知; the resulting string from HtmlEncode will show (when used in HTML) exactly that what you have input in the method. 来自HtmlEncode的结果字符串将显示(在HTML中使用时)与您在方法中输入的内容完全相同。 So do not use HTML entities in your input, because then that's exactly what you'll see in the resulting page. 因此,不要在输入中使用HTML实体,因为这正是您在结果页面中看到的内容。

If you want to show m² then just enter that inside the method. 如果你想显示m²,那么只需在方法内输入。 .NET will take care of the rest. .NET将负责其余部分。

Maybe unicode symbols would do the trick for you: http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html#super 也许unicode符号可以帮到你: http//tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html#super

For the superscripted two you would use ² 对于上标两个,你会使用² resulting in: ² 导致:²

You can write this way, 你可以这样写,

string item=HttpUtility.HtmlDecode("ml/min/1.73m²")

for more info on superscript you can see this link http://symbolcodes.tlt.psu.edu/bylanguage/mathchart.html#super 有关上标的更多信息,您可以看到此链接http://symbolcodes.tlt.psu.edu/bylanguage/mathchart.html#super

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

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