Asp.Net DropDownList 的撇号问题
我使用以下代码向 DropDownList 添加一条记录,
this.ddlLocation.Items.Add(new ListItem(hs.ToString(), ll.id));
这对于普通字符串可以正常工作,但是如果字符串中有撇号,它就会以 html 形式出现,因为
<option value="11">Queen&amp;apos;s University</option>
它应该是女王大学。我在传递字符串之前立即检查了该值,它应该是这样的。看起来它被编码了两次,因此原始的撇号被取出,然后是&符号退出字符。我不确定编码发生在哪里以及如何错过其中之一。
另外,我正在使用 .Net 4.0
谢谢,
为下拉菜单添加了完整的 html。
<div class="fieldCol">
<label for="peopleSearch_lawSchool">LawSchool</label>
<select name="ctl00$nrContentPlaceHolder$ddlLawSchool" id="nrContentPlaceHolder_ddlLawSchool" class="peopleSearch_lawSchool" name="peopleSearch_lawSchool">
<option value="0">All</option>
<option value="1">Boston University</option>
<option value="2">Columbia University</option>
<option value="3">Cornell Law School</option>
<option value="4">Dalhousie University</option>
<option value="5">HEC Montréal</option>
<option value="6">London School of Economics and Political Science</option>
<option value="7">Loyola University</option>
<option value="8">Magdalene College - Cambridge</option>
<option value="9">McGill University</option>
<option value="10">Osgoode Hall Law School</option>
<option value="11">Queen&amp;apos;s University</option>
<option value="12">Symbiosis Law College</option>
<option value="13">Université de Moncton</option>
<option value="14">Université de Montréal</option>
<option value="15">Université de Sherbrooke</option>
<option value="16">Université du Québec à Montréal</option>
<option value="17">Université Laval</option>
<option value="18">Université Paris X</option>
<option value="19">University of Alberta</option>
<option value="20">University of Birmingham</option>
<option value="21">University of British Columbia</option>
<option value="22">University of Bucharest</option>
<option value="23">University of Calgary</option>
<option value="24">University of California</option>
<option value="25">University of Cambridge</option>
<option value="26">University of Detroit Mercy School of Law</option>
<option value="27">University of Glasgow</option>
<option value="28">University of London</option>
<option value="29">University of London, England</option>
<option value="30">University of Manitoba</option>
<option value="31">University of New Brunswick</option>
<option value="32">University of Ottawa</option>
<option value="33">University of Oxford</option>
<option value="34">University of Pennsylvania</option>
<option value="35">University of Pune</option>
<option value="36">University of Toronto</option>
<option value="37">University of Victoria</option>
<option value="38">University of Western Ontario</option>
<option value="39">University of Windsor</option>
</select>
</div>
它使用的是 asp:dropdownlist
I'm adding a record to a DropDownList with the following code
this.ddlLocation.Items.Add(new ListItem(hs.ToString(), ll.id));
This works correctly for normal strings however if there is an apostrophe in the string it comes out in html as
<option value="11">Queen&apos;s University</option>
where it should have been Queen's University. I have checked the value immediately before passing the string and it's how it should be. It looks like it is being encoded twice so the original apostrope is taken out followed by the ampersand exit character. I'm not sure where the encodes are happening and how to miss one of them out.
Also I'm using .Net 4.0
Thanks
Added the full html for the drop down.
<div class="fieldCol">
<label for="peopleSearch_lawSchool">LawSchool</label>
<select name="ctl00$nrContentPlaceHolder$ddlLawSchool" id="nrContentPlaceHolder_ddlLawSchool" class="peopleSearch_lawSchool" name="peopleSearch_lawSchool">
<option value="0">All</option>
<option value="1">Boston University</option>
<option value="2">Columbia University</option>
<option value="3">Cornell Law School</option>
<option value="4">Dalhousie University</option>
<option value="5">HEC Montréal</option>
<option value="6">London School of Economics and Political Science</option>
<option value="7">Loyola University</option>
<option value="8">Magdalene College - Cambridge</option>
<option value="9">McGill University</option>
<option value="10">Osgoode Hall Law School</option>
<option value="11">Queen&apos;s University</option>
<option value="12">Symbiosis Law College</option>
<option value="13">Université de Moncton</option>
<option value="14">Université de Montréal</option>
<option value="15">Université de Sherbrooke</option>
<option value="16">Université du Québec à Montréal</option>
<option value="17">Université Laval</option>
<option value="18">Université Paris X</option>
<option value="19">University of Alberta</option>
<option value="20">University of Birmingham</option>
<option value="21">University of British Columbia</option>
<option value="22">University of Bucharest</option>
<option value="23">University of Calgary</option>
<option value="24">University of California</option>
<option value="25">University of Cambridge</option>
<option value="26">University of Detroit Mercy School of Law</option>
<option value="27">University of Glasgow</option>
<option value="28">University of London</option>
<option value="29">University of London, England</option>
<option value="30">University of Manitoba</option>
<option value="31">University of New Brunswick</option>
<option value="32">University of Ottawa</option>
<option value="33">University of Oxford</option>
<option value="34">University of Pennsylvania</option>
<option value="35">University of Pune</option>
<option value="36">University of Toronto</option>
<option value="37">University of Victoria</option>
<option value="38">University of Western Ontario</option>
<option value="39">University of Windsor</option>
</select>
</div>
It is using a asp:dropdownlist
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否可以抑制 DropDownList 中的编码,因此我建议您查看
hs
的编码位置,看看是否可以解决该问题。I'm not sure if you can suppress encoding in the DropDownList, so I'd recommend looking at where did
hs
get encoded to see if you can fix that.