如何在<%...%>内使用c#代码标签在asp.net页面上? [英] How to use c# code inside <% ... %> tags on asp.net page?
问题描述
我正在编写一个asp.net用户控件.它具有一个属性MoreReadingPage和绑定到它的两个控件:ObjectDataSource和Repeater.在中继器内部,我想显示一个超链接,其href属性设置为 FurtherReadingPage +?id =" + Eval("Id")
之类的内容.我不知道如何在页面的标记内执行此操作.我可以单独使用<%Eval("Id")%>
或<%Response.Write(FurtherReadingPage +?id =")%>
我不知道如何混合它们.
I'm writing an asp.net user control. It has a property, FurtherReadingPage, and two controls bound to it: ObjectDataSource and a Repeater. Inside the Repeater I would like to display a hyperlink with an href property set to something like FurtherReadingPage + "?id=" + Eval("Id")
. I don't know how to do it inside the page's markup. I can use <% Eval("Id") %>
or <% Response.Write(FurtherReadingPage + "?id=") %>
alone but I don't know how to mix them.
推荐答案
您可以这样做-
<asp:Hyperlink runat="Server" ID="hlLink" NavigateUrl='<%# FurtherReadingPage + "?Id=" + DataBinder.Eval(Container.DataItem, "Id") %>' />
这篇关于如何在<%...%>内使用c#代码标签在asp.net页面上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!