如何在 ASP 超链接中包含查询字符串
本文关键字:包含 查询 字符串 超链接 ASP | 更新日期: 2023-09-27 18:34:54
im 尝试在 asp.net 超链接中发送查询字符串 我不确定它是否可能? IM 循环访问集合,我想包含集合中每个对象的 ID。 IM 得到的错误是 p 在当前上下文中不存在。 这是我的代码
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="container" style="margin-top:50px;">
<asp:Label ID="label1" runat="server"></asp:Label>
<div class="jumbotron" style="margin:100px;width:900px">
<% foreach (var p in products)
{
%> <!-- loop through the list -->
<ul style="display:inline-block;width:250px;height:300px;list-style-type:none;border-style:solid">
<li ">
<p><%= p.ProductName %></p>
<p>€<%= p.Price %></p>
<img src="<%= p.MainProductImage %>" width="150";height="150";/>
<br />
<asp:HyperLink ID="details" runat="server" Text="Details" NavigateUrl='<%#string.Format("ProductDetails.aspx?ProductID={0}", p.ProductID);%>' />
</li>
</ul>
<%
}
%>
</div>
</div>
而不是<asp:HyperLink>
使用
<a href='<%=string.Format("ProductDetails.aspx?ProductID={0}", p.ProductID);%>' alt="Details" >Details</a>