从输出编码字符串prevent ASP.NET [英] Prevent ASP.NET from encoding strings on output
问题描述
我如何从列表项编码锚标签页面呈现的时候停止ASP.Net?
我有对象的集合。每个对象有一个链接属性。我做了一个foreach,并试图输出在BulletedList中的链接,但ASP EN codeD的所有环节。
你知道吗?谢谢!
下面是code的违规片段。当用户选择一个专业,我用的是SelectedIndexChange事件清除并添加链接到的BulletedList:
如果(SpecialtyList.SelectedIndex大于0)
{
PhysicianLinks.Items.Clear(); 的foreach(在文档医师DOC)
{
如果(doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
PhysicianLinks.Items.Add(新的ListItem(&下; A HREF = \\+ doc.Link +\\>中+ doc.FullName +&下; / A>中));
}
}
}
您可以使用中继器替换的BulletedList
而不是的PhysicianLinks.Items.Add(新的ListItem(< A HREF = \\+ doc.Link +\\>中+ doc.FullName +< / A&GT ;));
,添加doc.Link到一个列表对象,并用它来中继器绑定。您可以包括您在中继ItemTemplate中想要的任何HTML
像
的东西 列表<串GT;文档链接=新的List<串GT;();
如果(SpecialtyList.SelectedIndex大于0)
{
的foreach(在文档医师DOC)
{
如果(doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
docLinks.add(doc.Link);
}
}
Repeater1.DataSource =文档链接;
Repeater1.DataBind();
}
和ASPX
< UL>
< ASP:直放站ID =Repeater1=服务器>
<&ItemTemplate中GT;
<李>< A HREF =<%#Container.DataItem.ToString()%>><%#Container.DataItem.ToString()%>< / A>< /李&GT ;
< / ItemTemplate中>
< / ASP:直放站>
< / UL>
How can I stop ASP.Net from encoding anchor tags in List Items when the page renders?
I have a collection of objects. Each object has a link property. I did a foreach and tried to output the links in a BulletedList, but ASP encoded all the links.
Any idea? Thanks!
Here's the offending snippet of code. When the user picks a specialty, I use the SelectedIndexChange event to clear and add links to the BulletedList:
if (SpecialtyList.SelectedIndex > 0)
{
PhysicianLinks.Items.Clear();
foreach (Physician doc in docs)
{
if (doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));
}
}
}
You can replace the Bulletedlist with a repeater
Instead of PhysicianLinks.Items.Add(new ListItem("<a href=\"" + doc.Link + "\">" + doc.FullName + "</a>"));
, add doc.Link to a List Object and use it to bind the repeater. You can include any html you want in the repeater itemtemplate
Something like
List<string> docLinks=new List<string>();
if (SpecialtyList.SelectedIndex > 0)
{
foreach (Physician doc in docs)
{
if (doc.Specialties.Contains(SpecialtyList.SelectedValue))
{
docLinks.add(doc.Link) ;
}
}
Repeater1.DataSource=docLinks;
Repeater1.DataBind();
}
And In ASPX
<ul>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<li><a href="<%# Container.DataItem.ToString()%>"><%# Container.DataItem.ToString()%></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
这篇关于从输出编码字符串prevent ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!