如何在aspx页面中动态设置一个独立的(不在gridview中)超链接控件的navigateurl属性内联?
我试图做以下,但它没有奏效.
<asp:HyperLink id="MyLink" NavigateUrl="../mypage.aspx?id=<%= pageid %>" runat="server">My Page</asp:HyperLink>
解决方法
你可以在代码中执行此操作:
protected void Page_Load(object sender,EventArgs e) { if (!IsPostBack) { string pageid = "123"; MyLink.NavigateUrl = string.Format("../mypage.aspx?id={0}",pageid); } }
更新:
现在@Marko Ivanovski指出了这个超链接在GridView中的注释,我没有注意到,最简单的方法是使用数据绑定(<%#语法):
<asp:TemplateColumn> <ItemTemplate> <asp:HyperLink id="MyLink" NavigateUrl='<%# Eval("pageid","~/mypage.aspx?id={0}") %>' runat="server"> My Page </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn>
更新2:
你真的需要服务器端控制吗?怎么样:
<a href="<%= this.ResolveUrl("~/mypage.aspx?id=" + pageid) %>"> My Page </a>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。