【问题标题】:How to bind NavigateUrl property of Hyperlink dynamically如何动态绑定超链接的 NavigateUrl 属性
【发布时间】:2014-12-24 12:39:30
【问题描述】:

在我的 aspx 页面中,我使用了 HyperLink 控件。在导航属性中,我试图连接字符串 url 和查询字符串值。在渲染 html 代码时,我看不到任何导航值。所以我无法使用我在 aspx 页面中生成的链接进行导航。代码如下:

<asp:HyperLink ID="linkRecord" runat="server" Text="Show number of records"
  NavigateUrl='<%#String.Concat("~/ShowTables.aspx?ShowNumberOfRecords=Y&proj="
                 ,Request.QueryString["proj"]) %>' /> 

但是当 html 在页面中呈现时,我发现了以下代码

<a id="linkRecord">Show number of records</a>

谁能告诉我哪里做错了。

谢谢

【问题讨论】:

  • 您需要在某个时间点调用linkRecord.DataBind()(例如,在Render 中)以执行&lt;%# ... %&gt; 数据绑定表达式中的代码。
  • @Rahul Singh,感谢您帮助我 :)

标签: c# asp.net webforms


【解决方案1】:

不要尝试像那样绑定服务器控件,在后面的代码中进行。

<asp:HyperLink ID="linkRecord" runat="server" Text="Show number of records" /> 

现在在您的页面加载中放置:

linkRecord.NavigateUrl=String.Concat("~/ShowTables.aspx?ShowNumberOfRecords=Y&proj=", Request.QueryString["proj"]);

【讨论】:

    猜你喜欢
    • 2011-04-05
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    • 2012-12-08
    • 2013-07-20
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多